Exemplo n.º 1
0
        public static void Save(IResourceDataProvider[] nodes, bool useSubDirs, ResourceDataType resourceDataType, Window ownerWindow = null)
        {
            if (nodes == null)
                return;

            Tuple<ResourceData, string>[] files;
            try {
                files = GetFiles(GetResourceData(nodes, resourceDataType), useSubDirs).ToArray();
            }
            catch (Exception ex) {
                App.MsgBox.Instance.Show(ex);
                return;
            }
            if (files.Length == 0)
                return;

            var data = new ProgressVM(Dispatcher.CurrentDispatcher, new ResourceSaver(files));
            var win = new ProgressDlg();
            win.DataContext = data;
            win.Owner = ownerWindow ?? Application.Current.MainWindow;
            win.Title = files.Length == 1 ? dnSpy_Shared_Resources.SaveResource : dnSpy_Shared_Resources.SaveResources;
            var res = win.ShowDialog();
            if (res != true)
                return;
            if (!data.WasError)
                return;
            App.MsgBox.Instance.Show(string.Format(dnSpy_Shared_Resources.AnErrorOccurred, data.ErrorMessage));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets all resource data
 /// </summary>
 /// <param name="nodes">Nodes</param>
 /// <param name="resourceDataType">Type of data to get</param>
 /// <returns></returns>
 public static ResourceData[] GetResourceData(IResourceDataProvider[] nodes, ResourceDataType resourceDataType)
 {
     if (nodes == null)
     {
         return(Array.Empty <ResourceData>());
     }
     return(nodes.SelectMany(a => a.GetResourceData(resourceDataType)).ToArray());
 }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the nodes
        /// </summary>
        /// <param name="nodes">Nodes</param>
        /// <param name="useSubDirs">true to create sub directories, false to dump everything in the same folder</param>
        /// <param name="resourceDataType">Type of data to save</param>
        /// <param name="ownerWindow">Owner window</param>
        public static void Save(IResourceDataProvider[]?nodes, bool useSubDirs, ResourceDataType resourceDataType, Window?ownerWindow = null)
        {
            if (nodes is null)
            {
                return;
            }

            (ResourceData data, string filename)[] files;
Exemplo n.º 4
0
    private void SubtractOneRoomStat(ResourceDataType resourceData)
    {
        switch (resourceData.Rt)
        {
        case ResourceDataTypes._Credits:
            shipStats.Credits += -price[roomLevel - 1]; if (usedRoom == true)
            {
                shipStats.Credits += (int)(price[roomLevel - 1] * priceReducationPercent);
            }
            else
            {
                shipStats.Credits += price[roomLevel - 1];
            }
            break;

        case ResourceDataTypes._Energy:
            shipStats.Energy += new Vector3(-energy, -energy, -energy);
            shipStats.Energy += new Vector3(minPower[roomLevel - 1], 0, minPower[roomLevel - 1]);
            break;

        case ResourceDataTypes._Security:
            shipStats.Security += -security;
            break;

        case ResourceDataTypes._ShipWeapons:
            shipStats.ShipWeapons += -shipWeapons;
            break;

        case ResourceDataTypes._Crew:
            shipStats.CrewCurrent += new Vector3(-crew, -crew, -crew);
            break;

        case ResourceDataTypes._Food:
            shipStats.Food += -food;
            break;

        case ResourceDataTypes._FoodPerTick:
            shipStats.FoodPerTick += -foodPerTick;
            break;

        case ResourceDataTypes._HullDurability:
            shipStats.ShipHealthCurrent += new Vector2(-shipHealth, -shipHealth);
            break;

        case ResourceDataTypes._Payout:
            shipStats.Payout += -credits;
            break;

        default:
            Debug.LogError("Resource type: " + resourceData.resourceName + " not setup in RoomStats");
            break;
        }
    }
Exemplo n.º 5
0
        public static void Save(IResourceNode[] nodes, bool useSubDirs, ResourceDataType resourceDataType)
        {
            if (nodes == null)
            {
                return;
            }

            var infos = GetResourceData(nodes, resourceDataType);

            if (infos.Length == 1)
            {
                var info = infos[0];
                var name = ResourceUtils.FixFileNamePart(ResourceUtils.GetFileName(info.Name));
                var dlg  = new WF.SaveFileDialog {
                    RestoreDirectory = true,
                    ValidateNames    = true,
                    FileName         = name,
                };
                var ext = Path.GetExtension(name);
                dlg.DefaultExt = string.IsNullOrEmpty(ext) ? string.Empty : ext.Substring(1);
                if (dlg.ShowDialog() != WF.DialogResult.OK)
                {
                    return;
                }
                var ex = ResourceUtils.SaveFile(dlg.FileName, info.GetStream());
                if (ex != null)
                {
                    MainWindow.Instance.ShowMessageBox(string.Format("Could not save '{0}'\nERROR: {1}", dlg.FileName, ex.Message));
                }
            }
            else
            {
                var dlg = new WF.FolderBrowserDialog();
                if (dlg.ShowDialog() != WF.DialogResult.OK)
                {
                    return;
                }
                string baseDir = dlg.SelectedPath;
                foreach (var info in infos)
                {
                    var name     = ResourceUtils.GetCleanedPath(info.Name, useSubDirs);
                    var pathName = Path.Combine(baseDir, name);
                    var ex       = ResourceUtils.SaveFile(pathName, info.GetStream());
                    if (ex != null)
                    {
                        MainWindow.Instance.ShowMessageBox(string.Format("Could not save '{0}'\nERROR: {1}", pathName, ex.Message));
                        break;
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        public IEnumerable <ResourceData> GetResourceData(ResourceDataType type)
        {
            switch (type)
            {
            case ResourceDataType.Deserialized:
                return(GetDeserializedData());

            case ResourceDataType.Serialized:
                return(GetSerializedData());

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 7
0
    private void AddOneRoomStat(ResourceDataType resourceData)
    {
        switch (resourceData.Rt)
        {
        case ResourceDataTypes._Credits:
            shipStats.Credits += -price[roomLevel - 1];
            break;

        case ResourceDataTypes._Energy:
            shipStats.Energy += new Vector3(energy, energy, energy);
            shipStats.Energy += new Vector3(-minPower[roomLevel - 1], 0, -minPower[roomLevel - 1]);
            break;

        case ResourceDataTypes._Security:
            shipStats.Security += security;
            break;

        case ResourceDataTypes._ShipWeapons:
            shipStats.ShipWeapons += shipWeapons;
            break;

        case ResourceDataTypes._Crew:
            shipStats.CrewCurrent += new Vector3(crew, crew, crew);
            break;

        case ResourceDataTypes._Food:
            shipStats.Food += food;
            break;

        case ResourceDataTypes._FoodPerTick:
            shipStats.FoodPerTick += foodPerTick;
            break;

        case ResourceDataTypes._HullDurability:
            shipStats.ShipHealthCurrent += new Vector2(shipHealth, shipHealth);
            break;

        case ResourceDataTypes._Payout:
            shipStats.Payout += credits;
            break;

        default:
            Debug.LogError("Resource type: " + resourceData.resourceName + " not setup in RoomStats");
            break;
        }
    }
Exemplo n.º 8
0
    public ResourceDataType CloneData()
    {
        ResourceDataType clone = CreateInstance <ResourceDataType>();

        clone.resourceName = resourceName;
        clone.resourceIcon = resourceIcon;
        //clone.shapeType = shapeType;
        //clone.boundsUp = boundsUp;
        //clone.boundsDown = boundsDown;
        //clone.boundsLeft = boundsLeft;
        //clone.boundsRight = boundsRight;
        //clone.rotBoundsRight = rotBoundsRight;
        //clone.rotBoundsUp = rotBoundsUp;
        //clone.rotAdjustVal = rotAdjustVal;
        //clone.gridSpaces = gridSpaces;
        return(clone);
    }
Exemplo n.º 9
0
		public static void Save(IResourceNode[] nodes, bool useSubDirs, ResourceDataType resourceDataType) {
			if (nodes == null)
				return;

			var files = GetFiles(GetResourceData(nodes, resourceDataType), useSubDirs).ToArray();
			if (files.Length == 0)
				return;

			var data = new ProgressVM(MainWindow.Instance.Dispatcher, new ResourceSaver(files));
			var win = new ProgressDlg();
			win.DataContext = data;
			win.Owner = MainWindow.Instance;
			win.Title = files.Length == 1 ? "Save Resource" : "Save Resources";
			var res = win.ShowDialog();
			if (res != true)
				return;
			if (!data.WasError)
				return;
			MainWindow.Instance.ShowMessageBox(string.Format("An error occurred:\n\n{0}", data.ErrorMessage));
		}
Exemplo n.º 10
0
        public static void Save(IResourceNode[] nodes, bool useSubDirs, ResourceDataType resourceDataType)
        {
            if (nodes == null)
                return;

            var infos = GetResourceData(nodes, resourceDataType);
            if (infos.Length == 1) {
                var info = infos[0];
                var name = ResourceUtils.FixFileNamePart(ResourceUtils.GetFileName(info.Name));
                var dlg = new WF.SaveFileDialog {
                    RestoreDirectory = true,
                    ValidateNames = true,
                    FileName = name,
                };
                var ext = Path.GetExtension(name);
                dlg.DefaultExt = string.IsNullOrEmpty(ext) ? string.Empty : ext.Substring(1);
                if (dlg.ShowDialog() != WF.DialogResult.OK)
                    return;
                var ex = ResourceUtils.SaveFile(dlg.FileName, info.GetStream());
                if (ex != null)
                    MainWindow.Instance.ShowMessageBox(string.Format("Could not save '{0}'\nERROR: {1}", dlg.FileName, ex.Message));
            }
            else {
                var dlg = new WF.FolderBrowserDialog();
                if (dlg.ShowDialog() != WF.DialogResult.OK)
                    return;
                string baseDir = dlg.SelectedPath;
                foreach (var info in infos) {
                    var name = ResourceUtils.GetCleanedPath(info.Name, useSubDirs);
                    var pathName = Path.Combine(baseDir, name);
                    var ex = ResourceUtils.SaveFile(pathName, info.GetStream());
                    if (ex != null) {
                        MainWindow.Instance.ShowMessageBox(string.Format("Could not save '{0}'\nERROR: {1}", pathName, ex.Message));
                        break;
                    }
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Saves the nodes
        /// </summary>
        /// <param name="nodes">Nodes</param>
        /// <param name="useSubDirs">true to create sub directories, false to dump everything in the same folder</param>
        /// <param name="resourceDataType">Type of data to save</param>
        /// <param name="ownerWindow">Owner window</param>
        public static void Save(IResourceDataProvider[] nodes, bool useSubDirs, ResourceDataType resourceDataType, Window ownerWindow = null)
        {
            if (nodes == null)
            {
                return;
            }

            Tuple <ResourceData, string>[] files;
            try {
                files = GetFiles(GetResourceData(nodes, resourceDataType), useSubDirs).ToArray();
            }
            catch (Exception ex) {
                MsgBox.Instance.Show(ex);
                return;
            }
            if (files.Length == 0)
            {
                return;
            }

            var data = new ProgressVM(Dispatcher.CurrentDispatcher, new ResourceSaver(files));
            var win  = new ProgressDlg();

            win.DataContext = data;
            win.Owner       = ownerWindow ?? Application.Current.MainWindow;
            win.Title       = files.Length == 1 ? dnSpy_Contracts_DnSpy_Resources.SaveResource : dnSpy_Contracts_DnSpy_Resources.SaveResources;
            var res = win.ShowDialog();

            if (res != true)
            {
                return;
            }
            if (!data.WasError)
            {
                return;
            }
            MsgBox.Instance.Show(string.Format(dnSpy_Contracts_DnSpy_Resources.AnErrorOccurred, data.ErrorMessage));
        }
Exemplo n.º 12
0
 public static ResourceData[] GetResourceData(IResourceNode[] nodes, ResourceDataType resourceDataType)
 {
     return nodes.SelectMany(a => a.GetResourceData(resourceDataType)).ToArray();
 }
Exemplo n.º 13
0
        public override void SetResourceData(string resourceid, string dataname, ResourceDataType datatype, System.IO.Stream stream, Utility.StreamCopyProgressDelegate callback)
        {
            //Protect against session expired
            if (this.m_autoRestartSession && m_username != null && m_password != null)
                this.DownloadData(m_reqBuilder.GetSiteVersion());

            //Use the old code path if stream is under 50MB (implying seekable too)
            if (stream.CanSeek && stream.Length < 50 * 1024 * 1024)
            {
            #if DEBUG_LASTMESSAGE
                using (System.IO.Stream s = System.IO.File.Open("lastSaveData.bin", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                    Utility.CopyStream(stream, s);
            #endif
                    if (stream.CanSeek)
                        stream.Position = 0;

                    System.IO.MemoryStream outStream = new System.IO.MemoryStream();
            #if DEBUG_LASTMESSAGE
                try
                {
            #endif
                    System.Net.WebRequest req = m_reqBuilder.SetResourceData(resourceid, dataname, datatype, outStream, stream, callback);
                    req.Credentials = _cred;
                    outStream.Position = 0;

                    //TODO: We need a progress bar for the upload....
                    req.Timeout = 1000 * 60 * 15;
                    using (System.IO.Stream rs = req.GetRequestStream())
                    {
                        Utility.CopyStream(outStream, rs);
                        rs.Flush();
                    }
                    using (System.IO.Stream resp = req.GetResponse().GetResponseStream())
                    {
                        //Do nothing... there is no return value
                    }
            #if DEBUG_LASTMESSAGE
                }
                catch
                {
                    using (System.IO.Stream s = System.IO.File.OpenWrite("lastPost.txt"))
                        Utility.CopyStream(outStream, s);

                    throw;
                }
            #endif
            }
            else
            {
                //Dump to temp file
                string tmp = Path.GetTempFileName();
                try
                {
                    using (var fw = File.OpenWrite(tmp))
                    {
                        Utility.CopyStream(stream, fw);
                    }
                    var fi = new FileInfo(tmp);
                    NameValueCollection nvc = m_reqBuilder.SetResourceDataParams(resourceid, dataname, datatype);
                    nvc.Add("DATALENGTH", fi.Length.ToString());
                    HttpUploadFile(m_reqBuilder.HostURI, tmp, "DATA", "application/octet-stream", nvc, callback);
                }
                finally
                {
                    if (File.Exists(tmp))
                    {
                        try
                        {
                            File.Delete(tmp);
                            Debug.WriteLine("Deleted: " + tmp);
                        }
                        catch { }
                    }
                }
            }
        }
Exemplo n.º 14
0
 public override void SetResourceData(string resourceid, string dataname, ResourceDataType datatype, Stream stream, OSGeo.MapGuide.MaestroAPI.Utility.StreamCopyProgressDelegate callback)
 {
     MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService;
     MgByteReader reader = null;
     string tmpPath = null;
     //If stream is under our hard-coded limit (and it's seekable, which is how we're able to get that number), use the
     //overload of MgByteSource that accepts a byte[]. Otherwise dump the stream to a temp file and use the
     //file name overload (otherwise if our input stream happens to be several GBs, we run risk of
     //System.OutOfMemoryExceptions being thrown back at us)
     if (stream.CanSeek && stream.Length < (MAX_INPUT_STREAM_SIZE_MB * 1024 * 1024))
     {
         byte[] data = Utility.StreamAsArray(stream);
         MgByteSource source = new MgByteSource(data, data.Length);
         reader = source.GetReader();
     }
     else
     {
         tmpPath = Path.GetTempFileName();
         using (FileStream fs = File.OpenWrite(tmpPath))
         {
             stream.CopyTo(fs);
         }
         MgByteSource source = new MgByteSource(tmpPath);
         reader = source.GetReader();
     }
     try
     {
         res.SetResourceData(new MgResourceIdentifier(resourceid), dataname, datatype.ToString(), reader);
         LogMethodCall("MgResourceService::SetResourceData", true, resourceid, dataname, datatype.ToString(), "MgByteReader");
     }
     finally
     {
         if (!string.IsNullOrEmpty(tmpPath) && File.Exists(tmpPath))
         {
             //Be a responsible citizen and clean up our temp files when done
             try
             {
                 File.Delete(tmpPath);
             }
             catch { }
         }
     }
 }
Exemplo n.º 15
0
 public static ResourceData[] GetResourceData(IResourceDataProvider[] nodes, ResourceDataType resourceDataType)
 {
     if (nodes == null)
         return new ResourceData[0];
     return nodes.SelectMany(a => a.GetResourceData(resourceDataType)).ToArray();
 }
Exemplo n.º 16
0
 protected SaveResourcesContextMenuEntryBase(bool useSubDirs, ResourceDataType resourceDataType)
 {
     this.useSubDirs = useSubDirs;
     this.resourceDataType = resourceDataType;
 }
Exemplo n.º 17
0
        internal NameValueCollection SetResourceDataParams(string resourceid, string dataname, ResourceDataType datatype)
        {
            NameValueCollection param = new NameValueCollection();
            param.Add("OPERATION", "SETRESOURCEDATA");
            param.Add("VERSION", "1.0.0");
            param.Add("SESSION", m_sessionID);
            param.Add("CLIENTAGENT", m_userAgent);
            if (m_locale != null)
                param.Add("LOCALE", m_locale);

            param.Add("RESOURCEID", resourceid);
            param.Add("DATANAME", dataname);
            param.Add("DATATYPE", datatype.ToString());

            return param;
        }
Exemplo n.º 18
0
		public IEnumerable<ResourceData> GetResourceData(ResourceDataType type) {
			switch (type) {
			case ResourceDataType.Deserialized:
				return GetDeserialized();
			case ResourceDataType.Serialized:
				return GetSerialized();
			default:
				throw new InvalidOperationException();
			}
		}
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SetResourceDataPackageOperation"/> class.
 /// </summary>
 /// <param name="resId">The res id.</param>
 /// <param name="data">The data.</param>
 /// <param name="dataName">Name of the data.</param>
 /// <param name="dataType">Type of the data.</param>
 public SetResourceDataPackageOperation(string resId, string data, string dataName, ResourceDataType dataType)
     : base(resId)
 {
     this.OperationName = "SETRESOURCEDATA"; //NOXLATE
     this.Data = data;
     this.DataName = dataName;
     this.DataType = dataType;
 }
Exemplo n.º 20
0
        /// <summary>
        /// Convenience method for setting an associated resource data stream of this resource
        /// </summary>
        /// <param name="res"></param>
        /// <param name="dataName"></param>
        /// <param name="dataType"></param>
        /// <param name="inputStream"></param>
        public static void SetResourceData(this IResource res, string dataName, ResourceDataType dataType, Stream inputStream)
        {
            if (res.CurrentConnection == null)
                throw new ArgumentException(Strings.ERR_RESOURCE_NOT_ATTACHED);

            res.CurrentConnection.ResourceService.SetResourceData(res.ResourceID, dataName, dataType, inputStream);
        }
Exemplo n.º 21
0
 public IEnumerable <ResourceData> GetResourceData(ResourceDataType type) =>
 ResourceElementNode.GetSerializedData(resourceElement);
Exemplo n.º 22
0
		protected SaveResourcesCommandBase(bool useSubDirs, ResourceDataType resourceDataType) {
			this.useSubDirs = useSubDirs;
			this.resourceDataType = resourceDataType;
		}
Exemplo n.º 23
0
 public static ResourceData[] GetResourceData(IResourceNode[] nodes, ResourceDataType resourceDataType)
 {
     return(nodes.SelectMany(a => a.GetResourceData(resourceDataType)).ToArray());
 }
Exemplo n.º 24
0
        public System.Net.WebRequest SetResourceData(string id, string dataname, ResourceDataType datatype, System.IO.Stream outStream, System.IO.Stream content, Utility.StreamCopyProgressDelegate callback)
        {
            if (m_sessionID == null)
                throw new Exception("Connection is not yet logged in");

            NameValueCollection param = new NameValueCollection();
            param.Add("OPERATION", "SETRESOURCEDATA");
            param.Add("VERSION", "1.0.0");
            param.Add("SESSION", m_sessionID);
            param.Add("CLIENTAGENT", m_userAgent);
            if (m_locale != null)
                param.Add("LOCALE", m_locale);

            param.Add("RESOURCEID", id);
            param.Add("DATANAME", dataname);
            param.Add("DATATYPE", datatype.ToString());

            //This does not appear to be used anywhere in the MG WebTier code
            //anyway, set this if stream supports seeking
            if (content.CanSeek)
                param.Add("DATALENGTH", content.Length.ToString());

            string boundary;
            System.Net.WebRequest req = PrepareFormContent(outStream, out boundary);

            EncodeFormParameters(boundary, param, outStream);
            AppendFormContent("DATA", "content.bin", boundary, outStream, content, callback);

            req.ContentLength = outStream.Length;
            return req;
        }
Exemplo n.º 25
0
    public void UpdateRoomStats(ResourceDataType resourceData)
    {
        shipStats.roomBeingPlaced = gameObject;
        //SubtractOneRoomStat(resourceData);

        Resource resource = resources[0];

        switch (resourceData.Rt)
        {
        case ResourceDataTypes._Credits:
            credits += resourceChange;
            resource.activeAmount = credits;
            shipStats.Credits    += resourceChange;
            break;

        case ResourceDataTypes._Energy:
            energy += resourceChange;
            resource.activeAmount = energy;
            shipStats.Energy     += new Vector3(resourceChange, resourceChange, resourceChange);
            shipStats.Energy     += new Vector3(-minPower[roomLevel - 1], 0, -minPower[roomLevel - 1]);
            break;

        case ResourceDataTypes._Security:
            security += resourceChange;
            resource.activeAmount = security;
            shipStats.Security   += resourceChange;
            break;

        case ResourceDataTypes._ShipWeapons:
            shipWeapons           += resourceChange;
            resource.activeAmount  = shipWeapons;
            shipStats.ShipWeapons += resourceChange;
            break;

        case ResourceDataTypes._Crew:
            crew += resourceChange;
            resource.activeAmount  = crew;
            shipStats.CrewCurrent += new Vector3(resourceChange, resourceChange, resourceChange);
            break;

        case ResourceDataTypes._Food:
            food += resourceChange;
            resource.activeAmount = food;
            shipStats.Food       += resourceChange;
            break;

        case ResourceDataTypes._FoodPerTick:
            foodPerTick           += resourceChange;
            resource.activeAmount  = foodPerTick;
            shipStats.FoodPerTick += resourceChange;
            break;

        case ResourceDataTypes._HullDurability:
            shipHealth                  += resourceChange;
            resource.activeAmount        = shipHealth;
            shipStats.ShipHealthCurrent += new Vector2(resourceChange, resourceChange);
            break;

        case ResourceDataTypes._CrewMorale:
            morale += resourceChange;
            break;

        case ResourceDataTypes._Payout:
            credits += resourceChange;
            resource.activeAmount = credits;
            shipStats.Payout     += resourceChange;
            break;

        default:
            Debug.LogError("Resource type: " + resource.resourceType.resourceName + " not setup in RoomStats");
            break;
        }

        //roomDetailsMenu.UpdateCrewAssignment();
        //AddOneRoomStat(resourceData);
    }