Exemplo n.º 1
0
        // Save As
        private async Task <bool> SaveFileAs()
        {
            // #TODO: Check whether the user cancelled the action or it has actually failed
            StorageFile tempFile = await FileDataService.SaveAs(_data);

            if (tempFile != null)
            {
                File = tempFile;
                // Create a temp TextDataModel to make the changes in
                TextDataModel data = new TextDataModel();
                data.Text          = Data.Text;
                data.DocumentTitle = File.DisplayName + File.FileType;
                // Write the changes back to the Data property since it doesn't register single changed items otherwise
                Data         = data;
                PreviousData = data;
                RefreshTitlebarTitle();

                // Show Save Successful Notification
                Debug.WriteLine("Save File As File: Saving Successful");
                ShowUXMessage(1);
                SetEditedFalse();

                return(true);
            }
            else
            {
                // Show Save Failed Notification
                Debug.WriteLine("Save File As: Saving Failed");
                ShowUXMessage(2);
                return(false);
            }
        }
Exemplo n.º 2
0
        // Load without prompt (for when loading from Explorer)
        public static async Task <TextDataModel> LoadWithoutPrompt(StorageFile file)
        {
            TextDataModel data = null;

            if (file != null)
            {
                try
                {
                    data = new TextDataModel();

                    // Textdata
                    data.Text = await FileIO.ReadTextAsync(file);

                    data.DocumentTitle = file.DisplayName + file.FileType;

                    // Get Fast Access token
                    string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                    // #TODO: Check if the limit of 1000 has been reached and if yes, remove the 100 oldest entries
                    // #TODO: Store this token somewhere


                    Debug.WriteLine("File " + file.Name + " has been loaded");
                }
                catch
                {
                    Debug.WriteLine("Loading failed");
                }
            }

            return(data);
        }
        public TextDataModel GetTextData()
        {
            try
            {
                // Get the file path
                var filePath = this.appSetting.GetAppSetting(Constants.Constants.TextData);

                if (string.IsNullOrEmpty(filePath))
                {
                    throw new Exception("File Doesn't Exsist");
                }

                var localPath = this.uri.GetLocalPath(filePath);

                var data = this.fileIOService.ReadFile(localPath);
                textModel = this.helloWorldWrapper.GetTextData(data);
            }
            catch (FileNotFoundException)
            {
                throw; // textModel.ErrorMsg = fx.Message.ToString();
            }
            catch (NullReferenceException)
            {
                throw;//textModel.ErrorMsg = nr.Message.ToString();
            }
            catch (Exception)
            {
                throw;// textModel.ErrorMsg = ex.Message.ToString();
            }

            return(textModel);
        }
Exemplo n.º 4
0
        // Load
        public static async Task <LoadDataModel> Load()
        {
            LoadDataModel model = null;
            TextDataModel data  = null;

            model = new LoadDataModel();
            model.LoadSuccessful = false;

            FileOpenPicker picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.ViewMode = PickerViewMode.List;
            picker.FileTypeFilter.Add("*");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    data = new TextDataModel();

                    // Get the buffer of the file so we can also read it when encoded in different encoding from UTF8
                    // Fix with the help of Fred Bao's answer on https://social.msdn.microsoft.com/Forums/sqlserver/en-US/0f3cd056-a2e3-411b-8e8a-d2109255359a/uwpc-reading-ansi-text-file
                    IBuffer buffer = await FileIO.ReadBufferAsync(file);

                    DataReader dataReader  = DataReader.FromBuffer(buffer);
                    byte[]     fileContent = new byte[dataReader.UnconsumedBufferLength];
                    dataReader.ReadBytes(fileContent);
                    string readText = Encoding.UTF8.GetString(fileContent, 0, fileContent.Length);
                    // #TODO: Get the current encoding and display it in the TextDataModel


                    // Textdata
                    data.Text          = readText;
                    data.DocumentTitle = file.DisplayName + file.FileType;

                    // Get Fast Access token
                    GetFaToken(file);
                    // #TODO: Store this token somewhere


                    model.TextModel      = data;
                    model.File           = file;
                    model.LoadSuccessful = true;

                    Debug.WriteLine("File " + file.Name + " has been loaded");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Loading failed");
                    Debug.WriteLine(ex);
                    throw;
                }
            }

            return(model);
        }
Exemplo n.º 5
0
        // Save As
        public static async Task <StorageFile> SaveAs(TextDataModel data)
        {
            FileSavePicker picker = new FileSavePicker();

            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.FileTypeChoices.Add("Text Documents", new List <string>()
            {
                ".txt"
            });
            picker.FileTypeChoices.Add("All files", new List <string>()
            {
                "."
            });
            picker.DefaultFileExtension = ".txt";
            if (data.DocumentTitle != "")
            {
                picker.SuggestedFileName = data.DocumentTitle;
                // TODO: Get original file here as well
            }
            else
            {
                picker.SuggestedFileName = "Untitled";
            }


            StorageFile file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                // Prevent remote access to file until saving is done
                CachedFileManager.DeferUpdates(file);

                // Write the stuff to the file
                await FileIO.WriteTextAsync(file, data.Text);

                // Get Fast Access token
                string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                // #TODO: Check if the limit of 1000 has been reached and if yes, remove the 100 oldest entries
                // #TODO: Store this token somewhere

                // Let Windows know stuff is done
                FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);

                // DEBUG: Let programmer know what has happened
                if (status == FileUpdateStatus.Complete)
                {
                    Debug.WriteLine("File " + file.Name + " has been saved");
                }
                else
                {
                    Debug.WriteLine("File " + file.Name + " has NOT been saved");
                }
            }


            return(file);
        }
Exemplo n.º 6
0
        // Load
        public async Task <bool> Load()
        {
            TextDataModel data = await DataModel.Load();

            Data = new TextDataViewModel(data);

            //DocumentTitle = File.DisplayName + File.DisplayType;
            return(true);
        }
Exemplo n.º 7
0
        // Preperation Methods
        /// <summary>
        /// Sets up a new document for use in this ViewModel
        /// </summary>
        private void PrepareNewDocument()
        {
            TextDataModel emptyData = new TextDataModel();

            emptyData.DocumentTitle = ResourceExtensions.GetLocalized("UnititledLabel");
            Data = emptyData;
            File = null;
            SetEditedFalse();
            RefreshTitlebarTitle();
        }
        public static void StageNameXmlList_GetName(ref string __result, int id)
        {
            if (CheckDuel(id) || id == 1800000)
            {
                return;
            }
            Singleton <ContractLoader> .Instance.Init();

            __result = TextDataModel.GetText("ui_ContingecyLevel", (object)Singleton <ContractLoader> .Instance.GetLevel(id), (object)__result);
        }
Exemplo n.º 9
0
        public override void OnBattleEnd_alive()
        {
            base.OnBattleEnd_alive();
            if (Singleton <StageController> .Instance.stageType != StageType.Invitation || Singleton <StageController> .Instance.GetStageModel().GetFrontAvailableWave() != null)
            {
                return;
            }
            if (Singleton <StageController> .Instance.GetStageModel().ClassInfo.id == 40008)
            {
                int id = 240023;
                for (int index = 0; index < 2; ++index)
                {
                    Singleton <StageController> .Instance.OnEnemyDropBookForAdded(new DropBookDataForAddedReward(id));

                    DropBookXmlInfo data = Singleton <DropBookXmlList> .Instance.GetData(id);

                    if (data == null)
                    {
                        break;
                    }
                    SingletonBehavior <BattleManagerUI> .Instance.ui_emotionInfoBar.DropBook(new List <string>()
                    {
                        TextDataModel.GetText("BattleUI_GetBook", (object)data.Name)
                    });
                }
            }
            else
            {
                foreach (BattleUnitModel battleUnitModel in BattleObjectManager.instance.GetList(this._owner.faction == Faction.Player ? Faction.Enemy : Faction.Player))
                {
                    int emotionLevel = battleUnitModel.emotionDetail.EmotionLevel;
                    for (int key = emotionLevel; key >= 0; --key)
                    {
                        DropTable dropTable;
                        if (battleUnitModel.UnitData.unitData.DropTable.TryGetValue(key, out dropTable))
                        {
                            using (List <DropBookDataForAddedReward> .Enumerator enumerator = dropTable.DropRemakeCompare(emotionLevel).GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    Singleton <StageController> .Instance.OnEnemyDropBookForAdded(enumerator.Current);
                                }
                                break;
                            }
                        }
                    }
                }
                foreach (DropBookDataForAddedReward dataForAddedReward in Singleton <StageController> .Instance.GetDroppedBooksData())
                {
                    Singleton <StageController> .Instance.OnEnemyDropBookForAdded(new DropBookDataForAddedReward(dataForAddedReward.id, dataForAddedReward.isaddedreward));
                }
            }
        }
Exemplo n.º 10
0
        public async Task <TextDataModel> Read(int id)
        {
            var textData = await _unitOfWork.TextData.GetAsync(id);

            if (textData == null)
            {
                return(new TextDataModel());
            }

            var textDataModel = new TextDataModel {
                Id = textData.Id, Text = textData.Text
            };

            return(textDataModel);
        }
 public override void OnRoundEndTheLast()
 {
     base.OnRoundEndTheLast();
     if (!init)
     {
         this._owner.RecoverHP(this._owner.MaxHp);
         this._owner.RecoverBreakLife(1);
         this._owner.ResetBreakGauge();
         this._owner.breakDetail.nextTurnBreak = false;
         List <PassiveAbilityBase> list = this._owner.passiveDetail.PassiveList;
         list.Insert(0, new Zombie(this._owner));
         typeof(BattleUnitPassiveDetail).GetField("_passiveList", AccessTools.all).SetValue((object)this._owner.passiveDetail, (object)list);
         this._owner.UnitData.unitData.SetTempName(TextDataModel.GetText("Zombie_name"));
         init = true;
     }
 }
Exemplo n.º 12
0
 public void CheckSpecialCondition(StageClassInfo info)
 {
     if (GetContractCondition(OrangeCrossCondition, info))
     {
         Harmony_Patch.Progess.Orange_Path = 1;
         UIs.Add(TextDataModel.GetText("ui_RewardSpecial", TextDataModel.GetText("Condition_OrangeCross")));
     }
     if (EnsembleComplete)
     {
         if (Harmony_Patch.Progess.Ensemble_Complete == 0)
         {
             UIs.Add(TextDataModel.GetText("ui_RewardSpecial", TextDataModel.GetText("Condition_Ensemble")));
         }
         Harmony_Patch.Progess.Ensemble_Complete = 1;
     }
 }
Exemplo n.º 13
0
        // Load
        public static async Task <LoadDataModel> Load()
        {
            LoadDataModel model = null;
            TextDataModel data  = null;

            model = new LoadDataModel();
            model.LoadSuccessful = false;

            FileOpenPicker picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.ViewMode = PickerViewMode.List;
            picker.FileTypeFilter.Add("*");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    data = new TextDataModel();

                    // Textdata
                    data.Text = await FileIO.ReadTextAsync(file);

                    data.DocumentTitle = file.DisplayName + file.FileType;

                    // Get Fast Access token
                    GetFaToken(file);
                    // #TODO: Store this token somewhere


                    model.TextModel      = data;
                    model.File           = file;
                    model.LoadSuccessful = true;

                    Debug.WriteLine("File " + file.Name + " has been loaded");
                }
                catch
                {
                    Debug.WriteLine("Loading failed");
                }
            }

            return(model);
        }
        public TextDataModel GetTextData()
        {
            try
            {
                TextDataModel textData = null;

                this.restRequest.Resource = "HelloWorldAPI";
                this.restRequest.Method   = Method.GET;
                this.restClient.BaseUrl   = this.appSettings.GetAppSetting("HelloWorldAPIURL");

                this.restRequest.Parameters.Clear();


                var textDataModel = this.restClient.Execute <TextDataModel>(this.restRequest);


                if (textDataModel != null)
                {
                    if (textDataModel.Data != null)
                    {
                        textData = textDataModel.Data;
                    }
                    else
                    {
                        var errorDetail = string.IsNullOrWhiteSpace(textDataModel.Content) ? textDataModel.ErrorMessage : textDataModel.Content;


                        var errorMessage = " Error message : "
                                           + errorDetail + "\n\r HTTP Status Description : "
                                           + textDataModel.StatusDescription;

                        throw new Exception(errorMessage);
                    }
                }
                else
                {
                    //IF Exception throw and log
                }

                return(textData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 15
0
        private string GetParam()
        {
            string s = "";

            if (Level >= 1)
            {
                s += TextDataModel.GetText("Eileen_Production_param1");
            }
            if (Level >= 2)
            {
                s += TextDataModel.GetText("Eileen_Production_param2");
            }
            if (Level >= 3)
            {
                s += TextDataModel.GetText("Eileen_Production_param3");
            }
            return(s);
        }
Exemplo n.º 16
0
        // Drop Text
        public async Task <bool> DropText(DragEventArgs e)
        {
            bool success = false;

            if (e.DataView.Contains(StandardDataFormats.Text))
            {
                string tempText = await e.DataView.GetTextAsync();

                // Create a temporary datamodel to swap out so the ViewModel can track the change
                TextDataModel textDataModel = new TextDataModel();
                textDataModel.DocumentTitle = _data.DocumentTitle;
                textDataModel.Text          = (_data.Text + '\n' + '\n' + tempText);

                Data    = textDataModel;
                success = true;
            }

            return(success);
        }
Exemplo n.º 17
0
        public void CheckReward(StageClassInfo info)
        {
            if (Harmony_Patch.CheckDuel(info.id))
            {
                return;
            }
            if (Singleton <ContractLoader> .Instance.GetLevel(info.id) < 12)
            {
                return;
            }
            UIs = new List <string>();
            switch (info.id)
            {
            case (70001):
                Harmony_Patch.Progess.Philiph_Risk = 1;
                break;

            case (70002):
                Harmony_Patch.Progess.Eileen_Risk = 1;
                break;

            case (70007):
                Harmony_Patch.Progess.Jaeheon_Risk = 1;
                break;

            case (70008):
                Harmony_Patch.Progess.Elena_Risk = 1;
                break;

            case (70009):
                Harmony_Patch.Progess.Pluto_Risk = 1;
                break;
            }
            UIs.Add(TextDataModel.GetText("ui_RewardStage", Singleton <StageNameXmlList> .Instance.GetName(info.id)));
            CheckSpecialCondition(info);
            CheckRewardAchieved();
            Debug.SaveDebug();
            if (UIs.Count > 0)
            {
                UIAlarmPopup.instance.SetAlarmText(string.Join("\n", UIs));
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Loads a document for use in this ViewModel
        /// </summary>
        private async void LoadDocument()
        {
            // Just load
            TextDataModel data = await FileDataService.Load();

            if (data != null)
            {
                Data         = data;
                PreviousData = data;
                RefreshTitlebarTitle();
                SetEditedFalse();
                ShowUXMessage(3);
                //return true;
            }
            else
            {
                Debug.WriteLine("Load File: Dialog cancelled");
                //return false;
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initilize the ViewModel
        /// </summary>
        /// <param name="file">File that needs to be loaded. Leave empty for a new document</param>
        public async void Initialize(StorageFile file = null)
        {
            if (file != null)
            {
                TextDataModel data = await FileDataService.LoadWithoutPrompt(file);

                if (data != null)
                {
                    Data         = data;
                    PreviousData = data;
                    RefreshTitlebarTitle();
                }
            }
            else if (_data == null)
            {
                PrepareNewDocument();
            }

            SetEditedFalse();
            SetUXToggles();
        }
Exemplo n.º 20
0
        // Save
        public static async Task <bool> Save(TextDataModel data, StorageFile file)
        {
            // #TODO Build this method
            if (file != null)
            {
                try
                {
                    // Prevent remote access to file until saving is done
                    CachedFileManager.DeferUpdates(file);
                    // Write the stuff to the file
                    await FileIO.WriteTextAsync(file, data.Text);

                    // Let Windows know stuff is done
                    FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);

                    return(true);
                }
                catch { return(false); }
            }
            return(false);
        }
Exemplo n.º 21
0
        // Load
        public static async Task <TextDataModel> Load()
        {
            TextDataModel data = null;

            FileOpenPicker picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.ViewMode = PickerViewMode.List;
            picker.FileTypeFilter.Add("*");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    data = new TextDataModel();

                    // Textdata
                    data.Text = await FileIO.ReadTextAsync(file);

                    data.DocumentTitle = file.DisplayName + file.FileType;

                    // Get Fast Access token
                    string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                    // #TODO: Check if the limit of 1000 has been reached and if yes, remove the 100 oldest entries
                    // #TODO: Store this token somewhere


                    Debug.WriteLine("File " + file.Name + " has been loaded");
                }
                catch
                {
                    Debug.WriteLine("Loading failed");
                }
            }

            return(data);
        }
Exemplo n.º 22
0
        // Load without prompt (for when loading from Explorer)
        public static async Task <LoadDataModel> LoadWithoutPrompt(StorageFile file)
        {
            LoadDataModel model = null;
            TextDataModel data  = null;

            model = new LoadDataModel();
            model.LoadSuccessful = false;

            if (file != null)
            {
                try
                {
                    data = new TextDataModel();

                    // Textdata
                    data.Text = await FileIO.ReadTextAsync(file);

                    data.DocumentTitle = file.DisplayName + file.FileType;

                    // Get Fast Access token
                    GetFaToken(file);
                    // #TODO: Store this token somewhere


                    model.File           = file;
                    model.TextModel      = data;
                    model.LoadSuccessful = true;

                    Debug.WriteLine("File " + file.Name + " has been loaded");
                }
                catch
                {
                    Debug.WriteLine("Loading failed");
                }
            }

            return(model);
        }
        static void Main(string[] args)
        {
            var textModelRepository = new MongoAsyncRepository <TextDataModel>(new DataAccess.Models.MongoDbConfiguration()
            {
                ConnectionString = "mongodb://localhost:27017", Database = "TestDataStorage"
            });

            //for(int i = 0; i<100; i++)
            //{
            //    var testModel = new TextDataModel()
            //    {
            //        Name = "MyNameIs",
            //        Value = "Banksy"
            //    };

            //    textModelRepository.Save(testModel).Wait();
            //}

            var model = textModelRepository.GetById(Guid.Parse("7a724c04-5b8d-4e20-bf46-f0579bb14ad8")).Result;

            if (model == null)
            {
                model = new TextDataModel()
                {
                    Id    = Guid.Parse("7a724c04-5b8d-4e20-bf46-f0579bb14ad8"),
                    Name  = "Hello",
                    Value = "I'm new here"
                };
            }
            else
            {
                model.Name = "Ok, go next";
            }

            textModelRepository.Upsert(model).Wait();

            var nextpage = textModelRepository.GetPage(Guid.Parse("7a724c04-5b8d-4e20-bf46-f0579bb14ad8"), 10).Result.ToList();
        }