/// <summary>
        /// Preference Manager constructor - Get SharedPreferencesManager with given settings for name, mode and encryption in arguments
        /// </summary>
        /// <param name="context"></param>
        /// <param name="preferenceName"></param>
        /// <param name="mode"></param>
        /// <param name="secureKey"></param>
        /// <param name="encryptKeys"></param>
        /// <param name="encryptValues"></param>
        public SharedPreferencesManager(Context context, string preferenceName,
                                        FileCreationMode mode, string secureKey,
                                        bool encryptKeys, bool encryptValues)
        {
            try
            {
                _context = context;

                this._writer        = Cipher.GetInstance(TRANSFORMATION);
                this._reader        = Cipher.GetInstance(TRANSFORMATION);
                this._keyWriter     = Cipher.GetInstance(KEY_TRANSFORMATION);
                this._encryptKeys   = encryptKeys;
                this._encryptValues = encryptValues;

                InitCiphers(secureKey);

                _preferences = _context.GetSharedPreferences(preferenceName, mode);
                _editor      = _preferences.Edit();
            }
            catch (GeneralSecurityException e)
            {
                throw new SharedPreferencesManagerException(e);
            }
            catch (UnsupportedEncodingException e)
            {
                throw new SharedPreferencesManagerException(e);
            }
        }
        public static void MakePage([JetBrains.Annotations.NotNull] Document doc, [JetBrains.Annotations.NotNull] string dstdir,
                                    bool requireAll, FileCreationMode fileCreationMode,
                                    [CanBeNull] Section tocSection, [JetBrains.Annotations.NotNull] string csvCharacter)
        {
            string filename = null;

            if (fileCreationMode == FileCreationMode.Settlement && File.Exists(Path.Combine(dstdir, "totals.csv")))
            {
                filename = Path.Combine(dstdir, DirectoryNames.CalculateTargetdirectory(TargetDirectory.Root),
                                        "Totals.csv");
            }

            if (fileCreationMode == FileCreationMode.Household && File.Exists(Path.Combine(dstdir,
                                                                                           DirectoryNames.CalculateTargetdirectory(TargetDirectory.Reports), "TotalsPerLoadtype.csv")))
            {
                filename = Path.Combine(dstdir, DirectoryNames.CalculateTargetdirectory(TargetDirectory.Reports),
                                        "TotalsPerLoadtype.csv");
            }
            if (filename == null)
            {
                if (requireAll)
                {
                    throw new LPGException("Missing totals files.");
                }
                return;
            }

            var sec = doc.AddSection();

            var para = sec.AddParagraph();

            para.Format.Alignment   = ParagraphAlignment.Justify;
            para.Format.Font.Name   = "Times New Roman";
            para.Format.Font.Size   = 20;
            para.Format.Font.Bold   = true;
            para.Format.SpaceAfter  = "0.5cm";
            para.Format.SpaceBefore = "1cm";
            para.Format.Font.Color  = Colors.DarkGray;
            para.AddText("Totals");
            ChartPageBase.MakeTocEntry(tocSection, "Totals");
            para.AddBookmark("Totals");

            switch (fileCreationMode)
            {
            case FileCreationMode.Household:
                var totals = TotalsReader(filename, false, csvCharacter);
                SetHouseholdEntries(totals, doc, sec);
                SetPerDayTable(totals, doc, sec);
                SetMinMaxTable(totals, doc, sec);
                SetPerPersonTable(totals, doc, sec);
                SetPerPersonDayTable(totals, doc, sec);
                return;

            case FileCreationMode.Settlement:
                SetSettlementEntries(doc, sec, filename, csvCharacter);
                return;

            default: throw new LPGException("Forgotten File Creation Mode");
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public Stream CreateFile(string fileName, FileCreationMode fileCreationMode)
        {
            fileName = fileName.Replace('/', '\x2215');

            string filePath = GetFilePath(fileName);

            int tries = 0;

            while (tries < 5)
            {
                try
                {
                    FileMode fileMode = (fileCreationMode == FileCreationMode.ThrowIfFileExists) ? FileMode.CreateNew : (fileCreationMode == FileCreationMode.Overwrite) ? FileMode.Create : FileMode.Append;

                    return(new FileStream(filePath, fileMode, System.Security.AccessControl.FileSystemRights.Write, FileShare.Read, 4096, FileOptions.None, FilePermissions.CreateFilePermissions()));
                }
                catch (Exception exception)
                {
                    tries++;

                    if (tries >= 5)
                    {
                        return(HandleException(exception, filePath, fileName));
                    }

                    Thread.Sleep(3000);
                }
            }

            return(HandleException(new IOException(), filePath, fileName));
        }
Exemplo n.º 4
0
        public void Remove(string key, FileCreationMode mode = FileCreationMode.Private)
        {
            var sp = Context.GetSharedPreferences(SharedFile, mode).Edit();

            sp.Remove(key);
            sp.Apply();
        }
Exemplo n.º 5
0
        public void PutValue(string key, string value, FileCreationMode mode = FileCreationMode.Private)
        {
            var sp = Context.GetSharedPreferences(SharedFile, mode).Edit();

            sp.PutString(key, value);
            sp.Apply();
        }
Exemplo n.º 6
0
        public string GetValue(string key, string defValue, FileCreationMode mode = FileCreationMode.Private)
        {
            var sp    = Context.GetSharedPreferences(SharedFile, mode);
            var value = sp.GetString(key, defValue);

            return(value);
        }
 public static void init(Context context, string prefsname, FileCreationMode mode)
 {
     prefsUtil         = new SharedPreferencesUtil();
     prefsUtil.context = context;
     prefsUtil.prefs   = prefsUtil.context.GetSharedPreferences(prefsname, mode);
     prefsUtil.editor  = prefsUtil.prefs.Edit();
 }
Exemplo n.º 8
0
 public static extern IntPtr CreateFile(string lpFileName,
                                        FileAccessMode dwDesiredAccess,
                                        FileShareMode dwShareMode,
                                        IntPtr lpSecurityAttributes,
                                        FileCreationMode dwCreationDisposition,
                                        FileFlagAndAttribute dwFlagsAndAttributes,
                                        IntPtr hTemplateFile);
        Stream IDirectoryRepository.CreateFile(string fileName, FileCreationMode fileMode)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(fileName));

            Contract.Ensures(Contract.Result <Stream>().CanWrite, "Return stream must be writable.");

            return(default(Stream));
        }
Exemplo n.º 10
0
 public FileNamingParameters()
 {
     this.IncludeLevel = false;
     this.IncludeTimestamp = FileTimestampMode.Date;
     this.IncludeLogger = false;
     this.IncludeSession = true;
     this.IncludeSequence = false;
     CreationMode = FileCreationMode.AppendIfExisting;
 }
Exemplo n.º 11
0
 public static void Init(Context context, string prefsname, FileCreationMode mode)
 {
     mInstance = new SharePrefs
     {
         context = context,
         mSP     = context.GetSharedPreferences(prefsname, mode)
     };
     mInstance.editor = mInstance.mSP.Edit();
 }
Exemplo n.º 12
0
 public FileNamingParameters()
 {
     this.IncludeLevel     = false;
     this.IncludeTimestamp = FileTimestampMode.Date;
     this.IncludeLogger    = false;
     this.IncludeSession   = true;
     this.IncludeSequence  = false;
     CreationMode          = FileCreationMode.AppendIfExisting;
 }
Exemplo n.º 13
0
 public void StartNewFile(String name, FileCreationMode fileMode = FileCreationMode.Diff)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     CurrentBlock = new Block {
         Name = name, FileMode = fileMode, InlcudeHeader = fileMode == FileCreationMode.Diff
     };
 }
Exemplo n.º 14
0
        private bool CreateFile(FileCreationMode fileMode, string fileName, string content)
        {
            switch (fileMode)
            {
            case FileCreationMode.NotExists:
                return(CreateFileIfNotExists(fileName, content));

            //case FileMode.Diff:
            default:
                return(CreateFileIfDiff(fileName, content));
            }
        }
Exemplo n.º 15
0
        public FormFileCreation(IDE ide, FileCreationMode mode, string initialNodePath = null, string initialFileName = null)
        {
            InitializeComponent();
            SwitchMode(mode);

            _ide = ide;

            FillFolderList();

            SetInitialNodePath(initialNodePath);
            SetInitialFileName(initialFileName);
        }
Exemplo n.º 16
0
        // Private Methods

        /// <summary>
        /// Outputs the classification result as follows: {instanceName} {gold_class_label} {sys_class_label} {probability}.
        /// </summary>
        /// <param name="output_file">The location of the sys_output file.</param>
        /// <param name="vectors">A collection of vectors to classify.</param>
        /// <param name="classToclassId">A class for providing human-readable class labels.</param>
        /// <param name="heading">Usually, "Training" or "Test".</param>
        internal static double GenerateSysOutput(
            string output_file
            , FileCreationMode fileCreationMode
            , List <FeatureVector> vectors
            , TextIdMapper classToclassId
            , int[] goldClasses
            , int[] systemClasses
            , string[] details
            , string heading
            )
        {
            Debug.Assert(vectors != null && vectors.Count > 0);
            Debug.Assert(systemClasses != null && systemClasses.Length == vectors.Count);

            StreamWriter writer = null;

            try
            {
                switch (fileCreationMode)
                {
                case FileCreationMode.CreateNew: writer = File.CreateText(output_file); break;

                case FileCreationMode.Append:    writer = File.AppendText(output_file); break;

                default: throw new Exception($"Internal error: ProgramOutput.FileCreationMode with value '{fileCreationMode}' is not supported by this version of the application.");
                }

                writer.Write($"%%%%% {heading}:{Environment.NewLine}");

                // For each of the vectors, ...
                var confusionMatrix = new ConfusionMatrix(classToclassId.Count);
                for (int v_i = 0; v_i < vectors.Count; v_i++)
                {
                    string trueLabel = classToclassId[goldClasses[v_i]];
                    string sysLabel  = classToclassId[systemClasses[v_i]];

                    // Output the {true_class_label} {details}
                    writer.WriteLine($"{trueLabel}\t{sysLabel}\t{details[v_i]}");
                    confusionMatrix[goldClasses[v_i], systemClasses[v_i]]++;
                }
                writer.WriteLine();
                double accuracy = ReportAccuracy(confusionMatrix, classToclassId, heading);
                return(accuracy);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 17
0
        private void SwitchMode(FileCreationMode mode)
        {
            switch (mode)
            {
            case FileCreationMode.New:
                Text               = "Creating New File...";
                label_Where.Text   = "Where to Create:";
                button_Create.Text = "Create";
                break;

            case FileCreationMode.Saving:
                Text               = "Saving As...";
                label_Where.Text   = "Where to Save:";
                button_Create.Text = "Save";
                break;
            }
        }
 /// <summary>
 /// Preference Manager constructor - Get SharedPreferencesManager with given settings for name, mode and encryption in arguments
 /// </summary>
 /// <param name="context"></param>
 /// <param name="preferenceName"></param>
 /// <param name="mode"></param>
 /// <param name="secureKey"></param>
 /// <param name="encryptKeys"></param>
 /// <param name="encryptValues"></param>
 public SharedPreferencesManager(Context context, string preferenceName,
                                 FileCreationMode mode)
 {
     try
     {
         _context     = context;
         _preferences = _context.GetSharedPreferences(preferenceName, mode);
         _editor      = _preferences.Edit();
     }
     catch (GeneralSecurityException e)
     {
         throw new SharedPreferencesManagerException(e);
     }
     catch (UnsupportedEncodingException e)
     {
         throw new SharedPreferencesManagerException(e);
     }
 }
        /// <inheritdoc/>
        public Stream CreateFile(string fileName, FileCreationMode fileMode)
        {
            if (fileMode == FileCreationMode.ThrowIfFileExists && _ftpClient.FileExists(fileName))
            {
                throw new RepositoryConfigurationException(ConfigurationExceptionCategory.FileExists, this, String.Format(RepositoryExceptionMessage.FileAlreadyExists_1, fileName));
            }

            return(HandleExceptions(() =>
            {
                if (fileMode == FileCreationMode.Append)
                {
                    return _ftpClient.OpenAppend(fileName);
                }
                else
                {
                    return _ftpClient.OpenWrite(fileName);
                }
            }, fileName));
        }
Exemplo n.º 20
0
        private void SetSharedPreferenceString(string preferenceName, string sharedPreferenceKey, string preferenceValue, FileCreationMode fileCreationMode = FileCreationMode.Private)
        {
            var preferecence   = Application.Context.GetSharedPreferences(preferenceName, fileCreationMode);
            var preferenceEdit = preferecence.Edit();

            preferenceEdit.PutString(sharedPreferenceKey, preferenceValue);
            preferenceEdit.Commit();
        }
Exemplo n.º 21
0
 public static ISharedPreferences GetPreferences(string Name, FileCreationMode CreationMode = FileCreationMode.Private)
 {
     return(Application.Context.GetSharedPreferences(Name, CreationMode));
 }
Exemplo n.º 22
0
 private ISharedPreferences GetSharedPreferences(string v, FileCreationMode @private)
 {
     new Activity();
     return(Activity.GetSharedPreferences(v, @private));
 }
        /// <inheritdoc/>
        public Stream CreateFile(String fileName, FileCreationMode fileMode)
        {
            FileMode fm = fileMode == FileCreationMode.ThrowIfFileExists ? FileMode.CreateNew : fileMode == FileCreationMode.Overwrite ? FileMode.CreateNew : FileMode.Append;

            return(HandleExceptions(() => _sftpClient.Open(fileName, fm, FileAccess.Write), fileName));
        }
Exemplo n.º 24
0
 public static ISharedPreferences getSharedPreferences(this Context context, string name, FileCreationMode mode)
 {
     return(context.GetSharedPreferences(name, mode));
 }
Exemplo n.º 25
0
        public static ISharedPreferencesEditor GetPreferencesEditor(string Name, FileCreationMode CreationMode = FileCreationMode.Private)
        {
            ISharedPreferences Editor = GetPreferences(Name, CreationMode);

            return(Editor.Edit());
        }
Exemplo n.º 26
0
 public static Java.IO.File getDir(this Context context, string name, FileCreationMode mode)
 {
     return(context.GetDir(name, mode));
 }
Exemplo n.º 27
0
        public IEnumerable <string> AllKeys(FileCreationMode mode = FileCreationMode.Private)
        {
            var sp = Context.GetSharedPreferences(SharedFile, mode);

            return(sp.All.Keys);
        }
Exemplo n.º 28
0
        private string GetSharedPreferenceString(string preferenceName, string sharedPreferenceKey, string preferenceDefaultValue = "", FileCreationMode fileCreationMode = FileCreationMode.Private)
        {
            var preferecence = Application.Context.GetSharedPreferences(preferenceName, fileCreationMode);

            return(preferecence.GetString(sharedPreferenceKey, preferenceDefaultValue));
        }
Exemplo n.º 29
0
 public static ISharedPreferencesEditor GetUserInfoEditor(FileCreationMode CreationMode = FileCreationMode.Private)
 => LocalDatabase.GetPreferencesEditor(UserInfoName, CreationMode);
Exemplo n.º 30
0
 public static System.IO.Stream openFileOutput(this Context context, string name, FileCreationMode mode)
 {
     return(context.OpenFileOutput(name, mode));
 }