Пример #1
0
        public SaveAsOutput Execute(SaveAsInput input)
        {
            var output = new SaveAsOutput();

            if (this.dbFileAccessService.Exists(input.SrcPath))
            {
                this.dbFileAccessService.CopyDbFile(input.SrcPath, input.SavePath);
            }
            else
            {
                this.dbFileAccessService.CopyDbFile(input.MasterFilePath, input.SavePath);
            }

            this.dbMigrationService.Upgrade();
            this.projectSettingsAccessService.Update(
                input.StartDate,
                input.EndDate,
                input.Processes,
                input.Functions,
                input.Holidays,
                input.RestDays);

            this.memberAccessService.Update(
                input.Members);

            this.taskAccessService.Update(
                input.Tasks);

            this.processDependencyAccessService.Update(
                input.ProcessDependencies);

            this.functionDependencyAccessService.Update(
                input.FunctionDependencies);

            this.pertAccessService.Update(
                input.Edges);

            output.ProjectPath = input.SavePath;

            return(output);
        }
Пример #2
0
        /// <summary>
        /// output all the changes made with the editor to a new datadict file
        /// </summary>
        private void SaveAs_Execute()
        {
            //make sure all the elements that may hold old data before starting the file output process
            SaveAsOutput.Clear();
            SaveAsAttributeDescription.Clear();
            SaveAsFinalData.Clear();
            //store the header of the currently open file for later use
            SaveAsOutput = OpenFileBytes.Skip(0).Take(16 + (DDObjects.Count * 8)).ToList();

            //for every datadict object in the current file
            for (int i = 0; i < DDObjects.Count; i++)
            {
                ObservableCollection <DataDict_Attribute> SaveAsAttributes = new ObservableCollection <DataDict_Attribute>(DDObjects[i].DataDictObjects);
                //define the attributes associated to the current data dict object
                int SaveAsNumAttributes = DDObjects[i].NumOfAttributes;
                // loop through all atrributes, save to the output attribute description list and final data list
                for (int a = 0; a < SaveAsNumAttributes; a++)
                {
                    //add the attributes description the the attribute description array
                    SaveAsAttributeDescription.AddRange(DDObjects[i].DataDictObjects[a].Description.ToList <byte>());

                    //Set the new offset based on the current length of the final data block and write it to the attribute description array
                    byte[] cbytes = BitConverter.GetBytes(SaveAsFinalData.Count);
                    SaveAsAttributeDescription.AddRange(cbytes.Skip(0).Take(3).ToList());

                    //write the attribute type to the attribute description array
                    SaveAsAttributeDescription.Add(DDObjects[i].DataDictObjects[a].Type);

                    //based on the attribute type write the appropriate value bytes to the attribute description array
                    if (DDObjects[i].DataDictObjects[a].Type == 13)
                    {
                        SaveAsFinalData.AddRange(ReturnZeroPaddedString(DDObjects[i].DataDictObjects[a].Value));
                    }
                    else
                    {
                        SaveAsFinalData.AddRange(DDObjects[i].DataDictObjects[a].Value);
                    }
                }
            }
            //add the attribute description array to the final output array
            SaveAsOutput.AddRange(SaveAsAttributeDescription);
            //add the final data array to the final output array
            SaveAsOutput.AddRange(SaveAsFinalData);

            //update bytes 12-16 to represent the new length of data
            byte[] newdatalength = BitConverter.GetBytes(SaveAsFinalData.Count);

            //update the output bytes 4-8 with the new datablock length
            UpdateDatablockLength(newdatalength);


            //prepare to write the changes to a file by creating a new savefiledialog
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            //Set the window options to default to .datadict file format
            saveFileDialog1.Filter = "DeathSpank Data Files (*.datadict)| *.datadict";
            //set the save as window title
            saveFileDialog1.Title = "Save a DeathSpank Data File";
            //display the save as dialog option
            saveFileDialog1.ShowDialog();

            if (saveFileDialog1.FileName != "")
            {
                //Create a new filestream from the open file dialog options
                using (FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile())
                {
                    //create a binary writer to write to the filestream
                    BinaryWriter bw = new BinaryWriter(fs);
                    //Write data to the new file
                    bw.Write(SaveAsOutput.ToArray());

                    //flush and close the binarywriter
                    bw.Flush();
                    bw.Close();
                }
            }
        }