Esempio n. 1
0
        // Returns a hashcode.
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                int hash = 17;
                // Suitable nullity checks etc, of course :)
                hash = hash * 23 + OriginalName.GetHashCode();
                hash = hash * 23 + Domain.GetHashCode();

                foreach (IObject obj in objects)
                {
                    hash = hash * 23 + obj.GetHashCode();
                }

                foreach (IIntention intention in intentions)
                {
                    hash = hash * 23 + intention.GetHashCode();
                }

                foreach (IPredicate pred in initial)
                {
                    hash = hash * 23 + pred.GetHashCode();
                }

                foreach (IPredicate pred in goal)
                {
                    hash = hash * 23 + pred.GetHashCode();
                }

                return(hash);
            }
        }
Esempio n. 2
0
            protected override IEnumerator StartJobs()
            {
                //Logger.LogDebug($"NameJob.StartJobs: {this}");
                NameParts = new List <string>(new[] { OriginalName });

                if (SplitNames)
                {
                    NameParts = new List <string>(OriginalName.Split(TranslationHelper.SpaceSplitter,
                                                                     StringSplitOptions.RemoveEmptyEntries));
                }

                var jobs = new List <Coroutine>();

                foreach (var namePart in NameParts.Enumerate().ToArray())
                {
                    var i = namePart.Key;
                    JobStarted();
                    var job = StartCoroutine(Instance.TranslateName(namePart.Value, NameScope,
                                                                    result =>
                    {
                        if (result.Succeeded)
                        {
                            NameParts[i] = result.TranslatedText;
                        }
                        JobComplete();
                    }));
                    jobs.Add(job);
                }

                foreach (var job in jobs)
                {
                    //Logger.LogDebug($"NameJob.StartJobs: yield {job}");
                    yield return(job);
                }
            }
Esempio n. 3
0
 public UploadFIle(IFormFile file, bool ismusic)
 {
     File         = file;
     OriginalName = file.FileName;
     Extension    = "." + OriginalName.Split('.')[OriginalName.Split('.').Length - 1];
     IsMusic      = ismusic;
 }
Esempio n. 4
0
        public override void SetInputErrorMessages()
        {
            if (LanguageUid.IsEmptyGuid())
            {
                ErrorMessages.Add("language_uid_not_valid");
            }

            Name = Name.TrimOrDefault();
            if (Name.IsEmpty())
            {
                NameInput.ErrorMessage.Add("language_name_required_error_message");
                InputErrorMessages.AddRange(NameInput.ErrorMessage);
            }

            OriginalName = OriginalName.TrimOrDefault();
            if (OriginalName.IsEmpty())
            {
                OriginalNameInput.ErrorMessage.Add("language_original_name_required_error_message");
                InputErrorMessages.AddRange(OriginalNameInput.ErrorMessage);
            }

            if (IsoCode2.IsEmpty())
            {
                IsoCode2Input.ErrorMessage.Add("iso_code_2_required_error_message");
                InputErrorMessages.AddRange(IsoCode2Input.ErrorMessage);
            }

            if (IsoCode3.IsEmpty())
            {
                IsoCode3Input.ErrorMessage.Add("iso_code_3_required_error_message");
                InputErrorMessages.AddRange(IsoCode3Input.ErrorMessage);
            }
        }
Esempio n. 5
0
        public Query(string name, string file)
        {
            OriginalName = name.Trim();

            try
            {
                Name = Regex.Replace(OriginalName, @"[0-9]+\.", "").Trim();
            }
            catch (Exception)
            {
                Name = OriginalName;
            }

            try
            {
                var numString = OriginalName.Substring(0, OriginalName.IndexOf('.'));
                Number = int.Parse(numString);
            }
            catch (Exception)
            {
                Number = 0;
            }

            FilePath = file;

            var parser = new Parser();

            parser.ParseSql(FilePath);

            ExecutableSql = parser.ExecutableSql;
            SqlParameters = parser.SqlParameters;
            Comments      = parser.CommentLines;
            Inputs        = parser.QueryInputs;
        }
 public bool IsHisName(string unitName)
 {
     if (OriginalName == null || unitName == null)
     {
         return(false);
     }
     return(OriginalName.ToLower().Equals(unitName.ToLower()));
 }
Esempio n. 7
0
 public override void SetInputModelValues()
 {
     NameInput.Value         = Name.TrimOrDefault();
     OriginalNameInput.Value = OriginalName.TrimOrDefault();
     IsoCode2Input.Value     = IsoCode2;
     IsoCode3Input.Value     = IsoCode3;
     DescriptionInput.Value  = Description;
 }
Esempio n. 8
0
        /// <summary>
        /// Returns the hashcode for this <see cref="Parameter"/>.
        /// </summary>
        /// <returns>The hashcode value.</returns>
        public override int GetHashCode()
        {
            if (this.hashCode != null)
            {
                return(this.hashCode.Value);
            }

            // Set and return the hashcode
            return((this.hashCode = OriginalName.GetHashCode()).Value);
        }
Esempio n. 9
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (OriginalName != null ? OriginalName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Constructors != null ? Constructors.GetHashCode() : 0);
         return(hashCode);
     }
 }
Esempio n. 10
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (OriginalName != null ? OriginalName.GetHashCode() : 0);
         result = (result * 397) ^ (MapToName != null ? MapToName.GetHashCode() : 0);
         result = (result * 397) ^ CreationSettingType.GetHashCode();
         return(result);
     }
 }
            public Authenticator Convert(IIconResolver iconResolver)
            {
                var type = Type switch
                {
                    Type.Totp => AuthenticatorType.Totp,
                    Type.Hotp => AuthenticatorType.Hotp,
                    _ => throw new ArgumentOutOfRangeException()
                };

                string issuer;
                string username = null;

                if (!String.IsNullOrEmpty(Issuer))
                {
                    issuer = Issuer;

                    if (!String.IsNullOrEmpty(Email))
                    {
                        username = Email;
                    }
                }
                else
                {
                    var originalNameParts = OriginalName.Split(new[] { ':' }, 2);

                    if (originalNameParts.Length == 2)
                    {
                        issuer = originalNameParts[0];

                        if (issuer == "")
                        {
                            issuer = Email;
                        }
                        else
                        {
                            username = Email;
                        }
                    }
                    else
                    {
                        issuer = Email;
                    }
                }

                return(new Authenticator
                {
                    Issuer = issuer,
                    Username = username,
                    Type = type,
                    Secret = Authenticator.CleanSecret(Secret, type),
                    Counter = Counter,
                    Icon = iconResolver.FindServiceKeyByName(issuer)
                });
            }
        }
Esempio n. 12
0
        public override void SetInputErrorMessages()
        {
            Name = Name.TrimOrDefault();
            if (Name.IsEmpty())
            {
                NameInput.ErrorMessage.Add("language_name_required_error_message");
                InputErrorMessages.AddRange(NameInput.ErrorMessage);
            }

            OriginalName = OriginalName.TrimOrDefault();
            if (OriginalName.IsEmpty())
            {
                OriginalNameInput.ErrorMessage.Add("language_original_name_required_error_message");
                InputErrorMessages.AddRange(OriginalNameInput.ErrorMessage);
            }

            IsoCode2 = IsoCode2.TrimOrDefault();
            if (IsoCode2.IsEmpty())
            {
                IsoCode2Input.ErrorMessage.Add("iso_code_2_required_error_message");
                InputErrorMessages.AddRange(IsoCode2Input.ErrorMessage);
            }

            IsoCode3 = IsoCode3.TrimOrDefault();
            if (IsoCode3.IsEmpty())
            {
                IsoCode2Input.ErrorMessage.Add("iso_code_3_required_error_message");
                InputErrorMessages.AddRange(IsoCode2Input.ErrorMessage);
            }

            if (IsoCode2.IsNotEmpty() &&
                IsoCode2.Length != 2)
            {
                IsoCode2Input.ErrorMessage.Add("iso_code_2_must_be_2_character");
                InputErrorMessages.AddRange(IsoCode2Input.ErrorMessage);
            }

            if (IsoCode3.IsNotEmpty() &&
                IsoCode3.Length != 3)
            {
                IsoCode3Input.ErrorMessage.Add("iso_code_3_must_be_3_character");
                InputErrorMessages.AddRange(IsoCode3Input.ErrorMessage);
            }

            if (Icon == null)
            {
                IconInput.ErrorMessage.Add("icon_required_error_message");
                InputErrorMessages.AddRange(IconInput.ErrorMessage);
            }
            else if (Icon.ContentType != "image/png")
            {
                IconInput.ErrorMessage.Add("icon_file_type_error_message");
                InputErrorMessages.AddRange(IconInput.ErrorMessage);
            }
        }
        /// <summary>
        /// Determines whether the property passes a search or not
        /// </summary>
        public bool PassesSearch(string search)
        {
            if (string.IsNullOrEmpty(search))
            {
                return(true);
            }

            return
                (Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
                 OriginalName.Contains(search, StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 14
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Type != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (OriginalName.Length != 0)
            {
                hash ^= OriginalName.GetHashCode();
            }
            if (Table.Length != 0)
            {
                hash ^= Table.GetHashCode();
            }
            if (OriginalTable.Length != 0)
            {
                hash ^= OriginalTable.GetHashCode();
            }
            if (Schema.Length != 0)
            {
                hash ^= Schema.GetHashCode();
            }
            if (Catalog.Length != 0)
            {
                hash ^= Catalog.GetHashCode();
            }
            if (Collation != 0UL)
            {
                hash ^= Collation.GetHashCode();
            }
            if (FractionalDigits != 0)
            {
                hash ^= FractionalDigits.GetHashCode();
            }
            if (Length != 0)
            {
                hash ^= Length.GetHashCode();
            }
            if (Flags != 0)
            {
                hash ^= Flags.GetHashCode();
            }
            if (ContentType != 0)
            {
                hash ^= ContentType.GetHashCode();
            }
            return(hash);
        }
 /// <summary>
 /// after the user presses enter the text is converted to a name
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OriginalName_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (int)Keys.Enter)
     {
         name = new Name(OriginalName.Text);
         list = list + name;
         List.Items.Add(name);
         this.AmountOfNamesInList.Text = " Items in list:" + Convert.ToString(List.Items.Count);
         HasChanged = true;
         OriginalName.Clear();
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Id.GetHashCode();
         hashCode = (hashCode * 397) ^ (ContentType != null ? ContentType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (OriginalName != null ? OriginalName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Description != null ? Description.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Data != null ? Data.GetHashCode() : 0);
         return(hashCode);
     }
 }
Esempio n. 17
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Number;
         hashCode = (hashCode * 397) ^ (OriginalName != null ? OriginalName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Parameters != null ? Parameters.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Type != null ? Type.GetHashCode() : 0);
         return(hashCode);
     }
 }
Esempio n. 18
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = GeneratedLineNumber;
         hashCode = (hashCode * 397) ^ GeneratedColumnNumber;
         hashCode = (hashCode * 397) ^ OriginalLineNumber.GetHashCode();
         hashCode = (hashCode * 397) ^ OriginalColumnNumber.GetHashCode();
         hashCode = (hashCode * 397) ^ (OriginalName != null ? OriginalName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (OriginalFileName != null ? OriginalFileName.GetHashCode() : 0);
         return(hashCode);
     }
 }
Esempio n. 19
0
        private bool sameAsOriginal(string newName, bool shouldCompareUsingOriginalCase)
        {
            var newNameToCheck      = newName.Trim();
            var originalNameToCheck = OriginalName;

            if (!shouldCompareUsingOriginalCase)
            {
                newNameToCheck      = newNameToCheck.ToLower();
                originalNameToCheck = OriginalName.ToLower();
            }

            return(!string.IsNullOrEmpty(OriginalName) && string.Equals(originalNameToCheck, newNameToCheck));
        }
Esempio n. 20
0
        /// <summary>
        /// Returns the hashcode for this <see cref="Parameter"/>.
        /// </summary>
        /// <returns>The hashcode value.</returns>
        public override int GetHashCode()
        {
            if (m_hashCode != null)
            {
                return(m_hashCode.Value);
            }

            var hashCode = 0;

            // Set the hashcode
            hashCode = OriginalName.GetHashCode();

            // Set and return the hashcode
            return((m_hashCode = hashCode).Value);
        }
Esempio n. 21
0
            protected override IEnumerator StartJobs()
            {
                NameParts = ListPool <string> .Get();

                if (SplitNames)
                {
                    NameParts.AddRange(OriginalName.Split(TranslationHelper.SpaceSplitter,
                                                          StringSplitOptions.RemoveEmptyEntries));
                }
                else
                {
                    NameParts.Add(OriginalName);
                }

                var jobs = ListPool <Coroutine> .Get();

                try
                {
                    foreach (var namePart in NameParts.Enumerate().ToArray())
                    {
                        var i = namePart.Key;
                        JobStarted();
                        var job = StartCoroutine(Instance.TranslateName(namePart.Value, NameScope,
                                                                        result =>
                        {
                            if (result.Succeeded)
                            {
                                NameParts[i] = result.TranslatedText;
                            }
                            JobComplete();
                        }));
                        jobs.Add(job);
                    }

                    foreach (var job in jobs)
                    {
                        //Logger.LogDebug($"NameJob.StartJobs: yield {job}");
                        if (job != null)
                        {
                            yield return(job);
                        }
                    }
                }
                finally
                {
                    ListPool <Coroutine> .Release(jobs);
                }
            }
        /// <summary>
        /// Upon  clicking a item in the list the text boxes are filled with relevant info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void List_Click(object sender, EventArgs e)
        {
            if (List.SelectedItem != null)
            {
                OriginalName.Clear();
                LastName.Clear();
                RestOfName.Clear();
                Suffix.Clear();


                try
                {
                    this.OriginalName.Text = name.OriginalName;
                    this.LastName.Text     = name.Last;
                    this.RestOfName.Text   = name.Rest;
                    this.Suffix.Text       = name.Suffix;
                }
                catch (NullReferenceException)
                {
                }
            }
        }
Esempio n. 23
0
        private TransFileObject WrapObject(IPortableDeviceProperties properties, string objectId)
        {
            IPortableDeviceKeyCollection keys;

            properties.GetSupportedProperties(objectId, out keys);

            IPortableDeviceValues values;

            properties.GetValues(objectId, keys, out values);

            // Get the name of the object
            string name;
            var    property = new _tagpropertykey();

            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            property.pid   = 4;

            try {
                values.GetStringValue(property, out name);
            }
            catch (COMException e) {
                name = "(non name)";
            }

            // Get the original name of the object
            string OriginalName;

            property       = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            property.pid   = 12;
            try {
                values.GetStringValue(property, out OriginalName);
            }
            catch (COMException e) {
                OriginalName = "";
            }

            // Get last write time
            DateTime updatetime = new DateTime();

            property       = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            property.pid   = 19;
            try {
                string value;
                values.GetStringValue(property, out value);
                string format = "yyyy/MM/dd:HH:mm:ss.fff";
                updatetime = DateTime.ParseExact(value, format, null);
            }
            catch (COMException e) {
                //updatetime = DateTime.Now;
            }

            // Get the type of the object
            Guid contentType;

            property       = new _tagpropertykey();
            property.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
            property.pid   = 7;
            try {
                values.GetGuidValue(property, out contentType);
            }
            catch (COMException e) {
                return(new TransFileObject(name, null, updatetime, TransFileObject.ObjectKind.DIR));
            }

            Guid folderType     = new Guid(0x27E2E392, 0xA111, 0x48E0, 0xAB, 0x0C, 0xE1, 0x77, 0x05, 0xA0, 0x5F, 0x85);
            Guid functionalType = new Guid(0x99ED0160, 0x17FF, 0x4C44, 0x9D, 0x98, 0x1D, 0x7A, 0x6F, 0x94, 0x19, 0x21);

            if (contentType == folderType || contentType == functionalType)
            {
                return(new TransFileObject(name, objectId, updatetime, TransFileObject.ObjectKind.DIR));
            }

            if (OriginalName.CompareTo("") != 0)
            {
                name = OriginalName;
            }

            return(new TransFileObject(name, objectId, updatetime, TransFileObject.ObjectKind.FILE));
        }
 /// <summary>
 /// When the user clicks in this test box it is cleared
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OriginalName_Enter(object sender, EventArgs e)
 {
     OriginalName.Clear();
 }
Esempio n. 25
0
 public string GetExportName()
 {
     return(OriginalName.Replace('_', '-'));
 }
Esempio n. 26
0
 public override int GetHashCode()
 {
     return(OriginalName.GetHashCode());
 }
 /// <summary>
 /// Does the given value match with the name of the property?
 /// </summary>
 public bool MatchsName(string value)
 {
     return(Name.Equals(value, StringComparison.OrdinalIgnoreCase) ||
            OriginalName.Equals(value, StringComparison.OrdinalIgnoreCase));
 }
Esempio n. 28
0
        /// <summary>
        /// Synchronize new files from the vault storage provider.  The
        /// SyncPath specifies the path to download changed files from the
        /// vault storage provider to.  It may be populated with existing
        /// files, and only newer files should be transferred from the vault
        /// storage provider.
        ///
        /// This function is called from the transfer synchronization thread.
        /// </summary>
        /// <param name="AccountName">Supplies the account name.</param>
        /// <param name="SyncPath">Supplies the path to synchronize files to
        /// from the vault.  Existing files should be datestamp compared with
        /// the vault before being replaced.  File are downloaded from the
        /// vault, not uploaded, with this routine.</param>
        /// <param name="Context">Supplies a context handle.</param>
        /// <returns>TRUE on success.</returns>
        private static int OnSynchronizeAccountFromVault(string AccountName, string SyncPath, IntPtr Context)
        {
            try
            {
                //
                // Pass through to the default implementation if the connection
                // string is not defined in the database.
                //

                if (String.IsNullOrEmpty(StoreConnectionString))
                {
                    return(1);
                }

                string OriginalAccountName = AccountName;

                //
                // Canonicalize names to lowercase as the file store may be
                // case sensitive and maintaining a mapping table in the
                // database is problematic since the first save for a new
                // account may be observed before the players record for
                // that player is created (and a player could log in to two
                // servers simultaneously and create orphaned records that
                // way, or similarly during a database outage, etc.).
                //

                AccountName = AccountName.ToLowerInvariant();

                try
                {
                    bool DirCreated = false;
                    FileStoreDirectory StoreDirectory = Container.GetDirectoryReference(AccountName);

                    IEnumerable <string> FsFiles = null;
                    Dictionary <string, FileStoreFile> StoreFiles = new Dictionary <string, FileStoreFile>();

                    //
                    // Build an index of all files in the file store vault.
                    //

                    foreach (FileStoreFile StoreFile in StoreDirectory.GetFiles())
                    {
                        string[] Segments = StoreFile.Uri.Segments;

                        if (Segments.Length == 0)
                        {
                            continue;
                        }

                        string CharacterFileName = Segments[Segments.Length - 1].ToLowerInvariant();

                        if (!CharacterFileName.EndsWith(".bic"))
                        {
                            continue;
                        }

                        StoreFiles.Add(CharacterFileName, StoreFile);
                    }

                    //
                    // Enumerate file currently in the file system directory,
                    // transferring each corresponding file from the store
                    // directory if the modified date of the store file is
                    // after the modified date of the local file.
                    //

                    if (Directory.Exists(SyncPath))
                    {
                        FsFiles = Directory.EnumerateFiles(SyncPath);

                        foreach (string FsFileName in FsFiles)
                        {
                            DateTime      FsLastModified    = File.GetLastWriteTimeUtc(FsFileName);
                            string        CharacterFileName = Path.GetFileName(FsFileName);
                            string        Key = CharacterFileName.ToLowerInvariant();
                            FileStoreFile StoreFile;
                            string        TempFileName = null;

                            if (!StoreFiles.TryGetValue(Key, out StoreFile))
                            {
                                //
                                // This file exists locally but not in the file
                                // store vault.  Keep it (any excess files may be
                                // removed by explicit local vault cleanup).
                                //

                                continue;
                            }

                            //
                            // Transfer the file if the file store vault has a more
                            // recent version.
                            //

                            try
                            {
                                TempFileName = Path.GetTempFileName();

                                try
                                {
                                    using (FileStream FsFile = File.Open(TempFileName, FileMode.Create))
                                    {
                                        StoreFile.ReadIfModifiedSince(FsFile, new DateTimeOffset(FsLastModified));
                                    }

                                    try
                                    {
                                        File.Copy(TempFileName, FsFileName, true);
                                        File.SetLastWriteTimeUtc(FsFileName, StoreFile.LastModified.Value.DateTime);
                                    }
                                    catch
                                    {
                                        //
                                        // Clean up after a failed attempt to
                                        // instantiate copy file.
                                        //

                                        ALFA.SystemInfo.SafeDeleteFile(FsFileName);
                                        throw;
                                    }

                                    if (VerboseLoggingEnabled)
                                    {
                                        Logger.Log("ServerVaultConnector.OnSynchronizeAccountFromVault: Downloaded vault file '{0}\\{1}' with modified date {2} -> {3}.",
                                                   AccountName,
                                                   CharacterFileName,
                                                   FsLastModified,
                                                   File.GetLastWriteTimeUtc(FsFileName));
                                    }
                                }
                                catch (FileStoreConditionNotMetException)
                                {
                                    //
                                    // This file was not transferred because it is
                                    // already up to date.
                                    //

                                    Logger.Log("ServerVaultConnector.OnSynchronizeAccountFromVault: Vault file '{0}\\{1}' was already up to date with modified date {2}.",
                                               AccountName,
                                               CharacterFileName,
                                               FsLastModified);
                                }
                            }
                            finally
                            {
                                if (!String.IsNullOrEmpty(TempFileName))
                                {
                                    ALFA.SystemInfo.SafeDeleteFile(TempFileName);
                                }
                            }

                            //
                            // Remove this file from the list as it has already
                            // been accounted for (it is up to date or has just
                            // been transferred).

                            StoreFiles.Remove(Key);
                        }
                    }

                    //
                    // Sweep any files that were still not yet processed but
                    // existed in the file store vault.  These files are
                    // present on the canonical vault but have not yet been
                    // populated on the local vault, so transfer them now.
                    //

                    foreach (var StoreFile in StoreFiles.Values)
                    {
                        string[] Segments          = StoreFile.Uri.Segments;
                        string   CharacterFileName = Segments[Segments.Length - 1].ToLowerInvariant();
                        string   FsFileName        = SyncPath + Path.DirectorySeparatorChar + CharacterFileName;
                        string   TempFileName      = null;

                        if (!ALFA.SystemInfo.IsSafeFileName(CharacterFileName))
                        {
                            throw new ApplicationException("Unsafe filename '" + CharacterFileName + "' on vault for account '" + AccountName + "'.");
                        }

                        if (!DirCreated)
                        {
                            DirCreated = Directory.Exists(SyncPath);

                            //
                            // Create the sync directory if it does not exist.
                            // Attempt to preserve case from the vault store if
                            // possible, but fall back to using the case that
                            // the client specified at login time otherwise.
                            //

                            if (!DirCreated)
                            {
                                try
                                {
                                    string OriginalName;

                                    StoreFile.FetchAttributes();

                                    OriginalName = StoreFile.Metadata["OriginalFileName"];

                                    if (OriginalName != null && OriginalName.ToLowerInvariant() == AccountName + "/" + CharacterFileName)
                                    {
                                        OriginalName = OriginalName.Split('/').FirstOrDefault();

                                        DirectoryInfo Parent = Directory.GetParent(SyncPath);

                                        Directory.CreateDirectory(Parent.FullName + "\\" + OriginalName);

                                        if (VerboseLoggingEnabled)
                                        {
                                            Logger.Log("ServerVaultConnector.OnSynchronizeAccountFromVault: Created vault directory for account '{0}'.", OriginalName);
                                        }

                                        DirCreated = true;
                                    }
                                }
                                catch (Exception e)
                                {
                                    Logger.Log("ServerVaultConnector.OnSynchronizeAccountFromVault: Exception {0} recovering canonical case for creating vault directory '{1}', using account name from client instead.",
                                               e,
                                               OriginalAccountName);
                                }

                                if (!DirCreated)
                                {
                                    Directory.CreateDirectory(SyncPath);
                                    DirCreated = true;
                                }
                            }
                        }

                        try
                        {
                            TempFileName = Path.GetTempFileName();

                            using (FileStream FsFile = File.Open(TempFileName, FileMode.OpenOrCreate))
                            {
                                StoreFile.Read(FsFile);
                            }

                            try
                            {
                                File.Copy(TempFileName, FsFileName);
                                File.SetLastWriteTimeUtc(FsFileName, StoreFile.LastModified.Value.DateTime);
                            }
                            catch
                            {
                                //
                                // Clean up after a failed attempt to
                                // instantiate a new file.
                                //

                                ALFA.SystemInfo.SafeDeleteFile(FsFileName);
                                throw;
                            }

                            if (VerboseLoggingEnabled)
                            {
                                Logger.Log("ServerVaultConnector.OnSynchronizeAccountFromVault: Downloaded new vault file '{0}\\{1}' with modified date {2}.",
                                           AccountName,
                                           CharacterFileName,
                                           File.GetLastWriteTimeUtc(FsFileName));
                            }
                        }
                        finally
                        {
                            ALFA.SystemInfo.SafeDeleteFile(TempFileName);
                        }
                    }

                    return(1);
                }
                catch (Exception e)
                {
                    Logger.Log("ServerVaultConnector.OnSynchronizeAccountFromVault('{0}', '{1}'): Exception: {2}",
                               AccountName,
                               SyncPath,
                               e);

                    throw;
                }
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 29
0
        private bool sameAsOriginalInLowCase(string newName)
        {
            var newNameToLower = newName.ToLower().Trim();

            return(!string.IsNullOrEmpty(OriginalName) && string.Equals(OriginalName.ToLower(), newNameToLower));
        }
            public Authenticator Convert(IIconResolver iconResolver)
            {
                var type = Type switch
                {
                    Type.Totp => AuthenticatorType.Totp,
                    Type.Hotp => AuthenticatorType.Hotp,
                    Type.Blizzard => AuthenticatorType.Totp,
                    _ => throw new ArgumentOutOfRangeException()
                };

                string issuer;
                string username = null;

                if (!String.IsNullOrEmpty(Issuer))
                {
                    issuer = Type == Type.Blizzard ? BlizzardIssuer : Issuer;

                    if (!String.IsNullOrEmpty(Email))
                    {
                        username = Email;
                    }
                }
                else
                {
                    var originalNameParts = OriginalName.Split(new[] { ':' }, 2);

                    if (originalNameParts.Length == 2)
                    {
                        issuer = originalNameParts[0];

                        if (issuer == "")
                        {
                            issuer = Email;
                        }
                        else
                        {
                            username = Email;
                        }
                    }
                    else
                    {
                        issuer = Email;
                    }
                }

                var digits = Type == Type.Blizzard ? BlizzardDigits : type.GetDefaultDigits();

                string secret;

                if (Type == Type.Blizzard)
                {
                    var base32Secret = Base32Encoding.ToString(Secret.ToHexBytes());
                    secret = Authenticator.CleanSecret(base32Secret, type);
                }
                else
                {
                    secret = Authenticator.CleanSecret(Secret, type);
                }

                return(new Authenticator
                {
                    Issuer = issuer,
                    Username = username,
                    Type = type,
                    Secret = secret,
                    Counter = Counter,
                    Digits = digits,
                    Icon = iconResolver.FindServiceKeyByName(issuer)
                });
            }
        }