コード例 #1
0
ファイル: Data.cs プロジェクト: EleBrain/-CS-ZWJsonEditor
 public Data(string name, string summary, RecoveryType recovery, StateEffectType effect)
 {
     Name = name;
     Summary = summary;
     Recovery = recovery;
     Effect = effect;
 }
コード例 #2
0
        public ConsumableItem(string name, int value, Boolean stackable, String recoverytype, int recoveryamount, int amountvariance) : base(name, value, stackable)
        {
            itemName     = name;
            itemValue    = value;
            canStack     = stackable;
            thisItemType = ItemType.Consumable;

            thisRecoveryType           = (RecoveryType)Enum.Parse(typeof(RecoveryType), recoverytype);
            itemRecoveryAmount         = recoveryamount;
            itemRecoveryAmountVariance = amountvariance;
        }
コード例 #3
0
        private void CreateRecoveryFile(RecoveryType type)
        {
            IDocumentService doc = ServiceLocator.Current.GetInstance <IDocumentService>();

            if (doc.Document != null && (type == RecoveryType.UserSave || doc.Document.IsDirty))
            {
                NLogger.Info("Try to create recovery file for document with guid {0}", doc.Document.Guid);
                lock (doc.Document)
                {
                    ///load recoveryinfo.
                    this.LoadRecoveryFiles();
                    var existFile      = RecoveryInfo.RecoveryFiles.FirstOrDefault(x => x.Guid == doc.Document.Guid);
                    var duplicateIndex = 0;
                    var title          = string.IsNullOrEmpty(doc.Document.Title)
                        ? CommonDefine.Untitled
                        : doc.Document.Title;

                    if (existFile != null)
                    {
                        NLogger.Info("Last recovery file is exist, remove it from settings.");
                        duplicateIndex = existFile.DuplicateNameIndex;
                        RecoveryInfo.RecoveryFiles.Remove(existFile);
                        try
                        {
                            File.Delete(existFile.GetFullPath());
                            NLogger.Info("Remove last recovery file successfully.");
                        }
                        catch (Exception ex)
                        {
                            NLogger.Warn("Remove last recovery file failed.{0}", ex.ToString());
                        }
                    }
                    else
                    {
                        var topDuplicateIndex = RecoveryInfo.RecoveryFiles
                                                .Where(x => x.Filename == title)
                                                .OrderByDescending(x => x.DuplicateNameIndex)
                                                .FirstOrDefault();
                        if (topDuplicateIndex != null)
                        {
                            duplicateIndex = topDuplicateIndex.DuplicateNameIndex + 1;
                        }
                    }

                    var recoveryFile = new RecoveryFile
                    {
                        Guid               = doc.Document.Guid,
                        CreateTime         = DateTime.Now,
                        Type               = type,
                        Filename           = title,
                        DuplicateNameIndex = duplicateIndex,
                        Location           = GlobalData.AutoSaveFileLocation,
                        FileType           = (doc.Document.DocumentType == DocumentType.Library) ? ".libpn" : ".pn"
                    };

                    NLogger.Info("Make a new instance for Type RecoveryFile. Guid:{0} Type :{1} Filename:{2} Location:{3}",
                                 doc.Document.Guid,
                                 type,
                                 title,
                                 GlobalData.AutoSaveFileLocation);
                    RecoveryInfo.RecoveryFiles.Add(recoveryFile);
                    NLogger.Info("Add the new instance to RecoveryFiles.And try to save recovery files setting.");
                    SaveRecoveryFiles();
                    var fname = Path.Combine(GlobalData.AutoSaveFileLocation, recoveryFile.FullFilename);
                    try
                    {
                        doc.SaveCopyTo(fname);
                        NLogger.Info("SaveCopyTo {0} successfully.", fname);
                    }
                    catch (Exception ex)
                    {
                        NLogger.Warn("SaveCopyTo {0} failed.ex:{1}", fname, ex.ToString());
                    }
                }
            }
        }