示例#1
0
        public override void OnAdded(SPAddFieldOptions op)
        {
            using (new EnterExitLogger("CCSCascadedLookupField:OnAdded function"))
            {
                base.OnAdded(op);
                Update();

                if (!string.IsNullOrEmpty(AdditionalFields))
                {
                    string[] AdditionalFieldsArray = AdditionalFields.Split(new string[] { ";#" }, StringSplitOptions.None);
                    if (AdditionalFieldsArray.Length > 1)
                    {
                        for (int i = 0; i < AdditionalFieldsArray.Length - 1; i += 2)
                        {
                            if (!this.ParentList.Fields.ContainsField(this.Title + " : " + AdditionalFieldsArray[i]))
                            {
                                //create a new field
                                string        depLookUp      = this.ParentList.Fields.AddDependentLookup(this.Title + " : " + AdditionalFieldsArray[i], this.Id);
                                SPFieldLookup fieldDepLookup = (SPFieldLookup)this.ParentList.Fields.GetFieldByInternalName(depLookUp);

                                if (fieldDepLookup != null)
                                {
                                    fieldDepLookup.LookupWebId = this.LookupWebId;
                                    fieldDepLookup.LookupField = AdditionalFieldsArray[i + 1];
                                    fieldDepLookup.Update();
                                }
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        protected override int write(TagData tag, BinaryWriter w, string zone)
        {
            long   counterPos;
            uint   counter = 0;
            string vendor;

            if (AdditionalFields.ContainsKey(VENDOR_METADATA_ID))
            {
                vendor = AdditionalFields[VENDOR_METADATA_ID];
            }
            else
            {
                // Even when no existing field, vendor field is mandatory in OGG structure
                // => a file with no vendor is a FLAC file
                vendor = VENDOR_DEFAULT_FLAC;
            }

            w.Write((uint)vendor.Length);
            w.Write(Encoding.UTF8.GetBytes(vendor));

            counterPos = w.BaseStream.Position;
            w.Write((uint)0); // Tag counter placeholder to be rewritten in a few lines

            counter = writeFrames(tag, w);

            if (writeMetadataFramingBit)
            {
                w.Write((byte)1);                          // Framing bit (mandatory for OGG container)
            }
            // PADDING MANAGEMENT
            // Write the remaining padding bytes, if any detected during initial reading
            if (managePadding)
            {
                long paddingSizeToWrite;
                if (tag.PaddingSize > -1)
                {
                    paddingSizeToWrite = tag.PaddingSize;
                }
                else
                {
                    paddingSizeToWrite = TrackUtils.ComputePaddingSize(initialPaddingOffset, initialPaddingSize, initialPaddingOffset, w.BaseStream.Position);
                }
                if (paddingSizeToWrite > 0)
                {
                    for (int i = 0; i < paddingSizeToWrite; i++)
                    {
                        w.Write((byte)0);
                    }
                }
            }

            long finalPos = w.BaseStream.Position;

            w.BaseStream.Seek(counterPos, SeekOrigin.Begin);
            w.Write(counter);
            w.BaseStream.Seek(finalPos, SeekOrigin.Begin);

            return((int)counter);
        }
示例#3
0
        private async Task DeleteField(EntryFieldVm field)
        {
            AdditionalFields.Remove(field);
            if (!string.IsNullOrEmpty(field.Name))
            {
                await _mediator.Send(new DeleteFieldCommand { EntryId = Id, FieldName = field.Name });

                UpdateDirtyStatus(true);
            }
        }
示例#4
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var additionalFields = AdditionalFields.Split(',');
            var propValues       = new List <object> {
                value
            };

            foreach (var additionalField in additionalFields)
            {
                var prop = validationContext.ObjectType.GetProperty(additionalField);
                if (prop != null)
                {
                    var propValue = prop.GetValue(validationContext.ObjectInstance, null);
                    propValues.Add(propValue);
                }
                //else
                //{
                //    propValues.Add(null);
                //}
            }

            var controllerType = Assembly.GetExecutingAssembly().GetTypes()
                                 .FirstOrDefault(d => d.Name.ToLower() == (_controller + "Controller").ToLower());

            if (controllerType == null)
            {
                return(null);
            }

            var instance = Activator.CreateInstance(controllerType);

            var method = controllerType.GetMethod(_action);

            if (method == null)
            {
                return(null);
            }

            var response = method.Invoke(instance, propValues.ToArray());

            if (!(response is JsonResult))
            {
                return(null);
            }

            var isAvailable = false;
            var json        = response as JsonResult;

            bool.TryParse(json.Data.ToString(), out isAvailable);

            return(isAvailable ? null : new ValidationResult(FormatErrorMessage(validationContext.DisplayName)));
        }
示例#5
0
        protected override int write(TagData tag, BinaryWriter w, string zone)
        {
            long   counterPos;
            uint   counter = 0;
            string vendor;

            if (AdditionalFields.ContainsKey(VENDOR_METADATA_ID))
            {
                vendor = AdditionalFields[VENDOR_METADATA_ID];
            }
            else
            {
                // Even when no existing field, vendor field is mandatory in OGG structure
                // => a file with no vendor is a FLAC file
                vendor = VENDOR_DEFAULT_FLAC;
            }

            w.Write((uint)vendor.Length);
            w.Write(Encoding.UTF8.GetBytes(vendor));

            counterPos = w.BaseStream.Position;
            w.Write((uint)0); // Tag counter placeholder to be rewritten in a few lines

            counter = writeFrames(tag, w);

            if (writeMetadataFramingBit)
            {
                w.Write((byte)1);                          // Framing bit (mandatory for OGG container)
            }
            // NB : Foobar2000 adds a padding block of 2048 bytes here for OGG container, regardless of the type or size of written fields
            if (Settings.EnablePadding)
            {
                for (int i = 0; i < 2048; i++)
                {
                    w.Write((byte)0);
                }
            }

            long finalPos = w.BaseStream.Position;

            w.BaseStream.Seek(counterPos, SeekOrigin.Begin);
            w.Write(counter);
            w.BaseStream.Seek(finalPos, SeekOrigin.Begin);

            return((int)counter);
        }
示例#6
0
        /// <summary>
        ///     Adds an edge label and optional edge properties to the edge.
        /// </summary>
        /// <param name="label">Label of the edge</param>
        /// <param name="properties">
        ///     Properties of the edge as a tuple where Item1 is the property name
        ///     and Item2 is the property value.
        /// </param>
        /// <returns>This entity object.</returns>
        public Entity AddEdgeLabel(string label, List <Tuple <string, string> > properties = null)
        {
            if (HasEdgeLabel)
            {
                throw new InvalidOperationException("Only one edge label per edge is allowed!");
            }

            AdditionalFields.Add(new AdditionalField("link#maltego.link.label", null, label));
            AdditionalFields.Add(new AdditionalField("link#maltego.link.show-label", null, "1"));

            if (properties != null)
            {
                for (var i = 0; i < properties.Count; i++)
                {
                    AdditionalFields.Add(new AdditionalField("link#" + i, properties[i].Item1, properties[i].Item2));
                }
            }

            HasEdgeLabel = true;

            return(this);
        }
示例#7
0
        protected override int write(TagData tag, BinaryWriter w, string zone)
        {
            int result = 6;

            w.Write(Utils.BuildStrictLengthStringBytes(tag.Title, 32, 0, Encoding.UTF8));
            w.Write(Utils.BuildStrictLengthStringBytes(tag.Album, 32, 0, Encoding.UTF8));
            w.Write(Utils.BuildStrictLengthStringBytes(tag.Copyright, 32, 0, Encoding.UTF8));
            string str = "";

            if (AdditionalFields.ContainsKey("EMULATOR"))
            {
                str = AdditionalFields["EMULATOR"];
            }
            w.Write(Utils.BuildStrictLengthStringBytes(str, 32, 0, Encoding.UTF8));
            str = "";
            if (AdditionalFields.ContainsKey("DUMPER"))
            {
                str = AdditionalFields["DUMPER"];
            }
            w.Write(Utils.BuildStrictLengthStringBytes(str, 32, 0, Encoding.UTF8));
            w.Write(Utils.BuildStrictLengthStringBytes(tag.Comment, 256, 0, Encoding.UTF8));

            return(result);
        }
示例#8
0
文件: VGM.cs 项目: skolmer/atldotnet
        // Write GD3 tag
        protected override int write(TagData tag, BinaryWriter w, string zone)
        {
            byte[] endString = new byte[2] {
                0, 0
            };
            int      result = 11; // 11 field to write
            long     sizePos;
            string   str;
            Encoding unicodeEncoder = Encoding.Unicode;

            w.Write(Utils.Latin1Encoding.GetBytes(GD3_SIGNATURE));
            w.Write(0x00000100); // Version number

            sizePos = w.BaseStream.Position;
            w.Write(0);

            w.Write(unicodeEncoder.GetBytes(tag.Title));
            w.Write(endString); // Strings must be null-terminated
            str = "";
            if (AdditionalFields.ContainsKey("TITLE_J"))
            {
                str = AdditionalFields["TITLE_J"];
            }
            w.Write(unicodeEncoder.GetBytes(str));
            w.Write(endString);

            w.Write(unicodeEncoder.GetBytes(tag.Album));
            w.Write(endString);
            str = "";
            if (AdditionalFields.ContainsKey("GAME_J"))
            {
                str = AdditionalFields["GAME_J"];
            }
            w.Write(unicodeEncoder.GetBytes(str));
            w.Write(endString);

            str = "";
            if (AdditionalFields.ContainsKey("SYSTEM"))
            {
                str = AdditionalFields["SYSTEM"];
            }
            w.Write(unicodeEncoder.GetBytes(str));
            w.Write(endString);
            str = "";
            if (AdditionalFields.ContainsKey("SYSTEM_J"))
            {
                str = AdditionalFields["SYSTEM_J"];
            }
            w.Write(unicodeEncoder.GetBytes(str));
            w.Write(endString);

            w.Write(unicodeEncoder.GetBytes(tag.Artist));
            w.Write(endString);
            str = "";
            if (AdditionalFields.ContainsKey("AUTHOR_J"))
            {
                str = AdditionalFields["AUTHOR_J"];
            }
            w.Write(unicodeEncoder.GetBytes(str));
            w.Write(endString);

            string dateStr = "";

            if (Date != DateTime.MinValue)
            {
                dateStr = Date.ToString("yyyy/MM/dd");
            }
            else if (tag.RecordingYear != null && tag.RecordingYear.Length == 4)
            {
                dateStr = tag.RecordingYear;
                if (tag.RecordingDayMonth != null && tag.RecordingDayMonth.Length >= 4)
                {
                    dateStr += "/" + tag.RecordingDayMonth.Substring(tag.RecordingDayMonth.Length - 2, 2) + "/" + tag.RecordingDayMonth.Substring(0, 2);
                }
            }
            w.Write(unicodeEncoder.GetBytes(dateStr));
            w.Write(endString);

            str = "";
            if (AdditionalFields.ContainsKey("DUMPER"))
            {
                str = AdditionalFields["DUMPER"];
            }
            w.Write(unicodeEncoder.GetBytes(str));
            w.Write(endString);

            w.Write(unicodeEncoder.GetBytes(tag.Comment));
            w.Write(endString);

            w.Write(endString); // Is supposed to be there, according to sample files

            int size = (int)(w.BaseStream.Position - sizePos - 4);

            w.BaseStream.Seek(sizePos, SeekOrigin.Begin);
            w.Write(size);

            return(result);
        }
示例#9
0
        private TagData toTagData()
        {
            TagData result = new TagData();

            result.Title              = Title;
            result.Artist             = Artist;
            result.Composer           = Composer;
            result.Comment            = Comment;
            result.Genre              = Genre;
            result.OriginalArtist     = OriginalArtist;
            result.OriginalAlbum      = OriginalAlbum;
            result.GeneralDescription = Description;
            result.Rating             = (Popularity * 5).ToString();
            result.Copyright          = Copyright;
            result.Publisher          = Publisher;
            if (!PublishingDate.Equals(DateTime.MinValue))
            {
                result.PublishingDate = TrackUtils.FormatISOTimestamp(PublishingDate);
            }
            result.AlbumArtist = AlbumArtist;
            result.Conductor   = Conductor;
            if (!Date.Equals(DateTime.MinValue))
            {
                result.RecordingDate = TrackUtils.FormatISOTimestamp(Date);
            }
            result.RecordingYear            = Year.ToString();
            result.Album                    = Album;
            result.TrackNumber              = TrackNumber.ToString();
            result.TrackTotal               = TrackTotal.ToString();
            result.DiscNumber               = DiscNumber.ToString();
            result.DiscTotal                = DiscTotal.ToString();
            result.ChaptersTableDescription = ChaptersTableDescription.ToString();

            result.Chapters = new List <ChapterInfo>();
            foreach (ChapterInfo chapter in Chapters)
            {
                result.Chapters.Add(new ChapterInfo(chapter));
            }

            if (Lyrics != null)
            {
                result.Lyrics = new LyricsInfo(Lyrics);
            }

            foreach (string s in AdditionalFields.Keys)
            {
                result.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, s, AdditionalFields[s]));
            }

            // Detect and tag deleted Additional fields (=those which were in initialAdditionalFields and do not appear in AdditionalFields anymore)
            foreach (string s in initialAdditionalFields)
            {
                if (!AdditionalFields.ContainsKey(s))
                {
                    MetaFieldInfo metaFieldToDelete = new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, s, "");
                    metaFieldToDelete.MarkedForDeletion = true;
                    result.AdditionalFields.Add(metaFieldToDelete);
                }
            }

            result.Pictures = new List <PictureInfo>();
            if (currentEmbeddedPictures != null)
            {
                foreach (PictureInfo targetPic in currentEmbeddedPictures)
                {
                    targetPic.TransientFlag = 0;
                }
            }

            if (initialEmbeddedPictures != null && currentEmbeddedPictures != null)
            {
                foreach (PictureInfo picInfo in initialEmbeddedPictures)
                {
                    // Detect and tag deleted pictures (=those which were in initialEmbeddedPictures and do not appear in embeddedPictures anymore)
                    if (!currentEmbeddedPictures.Contains(picInfo))
                    {
                        PictureInfo picToDelete = new PictureInfo(picInfo);
                        picToDelete.MarkedForDeletion = true;
                        result.Pictures.Add(picToDelete);
                    }
                    else // Only add new additions (pictures identical to initial list will be kept, and do not have to make it to the list, or else a duplicate will be created)
                    {
                        foreach (PictureInfo targetPic in currentEmbeddedPictures)
                        {
                            if (targetPic.Equals(picInfo))
                            {
                                // Compare picture contents
                                targetPic.ComputePicHash();

                                if (targetPic.PictureHash != picInfo.PictureHash)
                                {
                                    // A new picture content has been defined for an existing location
                                    result.Pictures.Add(targetPic);

                                    PictureInfo picToDelete = new PictureInfo(picInfo);
                                    picToDelete.MarkedForDeletion = true;
                                    result.Pictures.Add(picToDelete);
                                }

                                targetPic.TransientFlag = 1;
                            }
                        }
                    }
                }

                if (currentEmbeddedPictures != null)
                {
                    foreach (PictureInfo targetPic in currentEmbeddedPictures)
                    {
                        if (0 == targetPic.TransientFlag) // Entirely new pictures without equivalent in initialEmbeddedPictures
                        {
                            result.Pictures.Add(targetPic);
                        }
                    }
                }
            }

            return(result);
        }
示例#10
0
 private void AddField()
 {
     AdditionalFields.Add(new EntryFieldVm(_cryptography));
     AdditionalFieldSelectedIndex = AdditionalFields.Count - 1;
 }
示例#11
0
        /// <summary>
        /// Overridden IsValid function
        /// </summary>
        /// <param name="value"></param>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            string connection = OtherConfig.CosSSMSConnString;
            DbContextOptions <CosDbContext>        dbContextOption        = new DbContextOptions <CosDbContext>();
            DbContextOptionsBuilder <CosDbContext> dbContextOptionBuilder = new DbContextOptionsBuilder <CosDbContext>(dbContextOption);
            CosDbContext dbContext = new CosDbContext(dbContextOptionBuilder.UseSqlServer(connection).Options);

            // Find the controller passed in constructor
            var controller = GetControllerList().FirstOrDefault(x => x.Name == string.Format("{0}Controller", this.RouteData["controller"]));

            if (controller == null)
            {
                // Default behavior of IsValid when no controller is found.
                return(ValidationResult.Success);
            }
            List <Type> proTypeList = new List <Type>()
            {
                value.GetType()
            };
            List <object> proList = new List <object>()
            {
                value
            };

            if (!string.IsNullOrWhiteSpace(AdditionalFields))
            {
                var fields = AdditionalFields.Split(',', StringSplitOptions.RemoveEmptyEntries);
                proTypeList.AddRange(validationContext.ObjectType.GetProperties().Where(info => fields.Any(s => info.Name.Contains(s))).Select(info => info.PropertyType));

                proList.AddRange(validationContext.ObjectType.GetProperties().Where(info => fields.Any(s => info.Name.Contains(s))).Select(info => info.GetValue(validationContext.ObjectInstance)));
            }

            // Find the Method passed in constructor
            var mi = controller.GetMethod(this.RouteData["action"].ToString(), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, proTypeList.ToArray(), null);

            if (mi == null)
            {
                // Default behavior of IsValid when action not found
                return(ValidationResult.Success);
            }

            // Create instance of the controller to be able to call non static validation method
            var instance = Activator.CreateInstance(controller, dbContext);

            // invoke the method on the controller with value and "AdditionalFields"
            JsonResult result = mi.Invoke(instance, proList.ToArray()) is Task <object> task ? (JsonResult)task.Result : (JsonResult)mi.Invoke(instance, proList.ToArray());

            // Return success or the error message string from CustomRemoteAttribute
            if (!(result.Value is string errorMessaqe))
            {
                bool isValid;
                try
                {
                    isValid = (bool)result.Value;
                }
                catch (Exception)
                {
                    isValid = false;
                }
                return(isValid ? ValidationResult.Success : new ValidationResult(base.ErrorMessageString));
            }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var propValues = new List <object> {
                value
            };

            if (!string.IsNullOrWhiteSpace(AdditionalFields))
            {
                var additionalFields = AdditionalFields.Split(',');
                propValues.AddRange(additionalFields
                                    .Select(additionalField => validationContext.ObjectType.GetProperty(additionalField))
                                    .Where(prop => prop != null)
                                    .Select(prop => prop.GetValue(validationContext.ObjectInstance, null)));
            }
            else if (propValues.Count == 1 && propValues.First() == null)
            {
                return(new ValidationResult("[RemoteClientServerAttribute] Nie można walidować właściwości o wartości null"));
            }

            // Pobierz kontroler używając Reflection
            var controller = Assembly.GetExecutingAssembly().GetTypes()
                             .FirstOrDefault(type => string.Equals(type.Name, $"{RouteData["controller"].ToString()}Controller", StringComparison.CurrentCultureIgnoreCase));

            // Pobierz metodę akcji zawierającą logikę walidacji
            var action = controller?.GetMethods()
                         .FirstOrDefault(method => string.Equals(method.Name, RouteData["action"].ToString(), StringComparison.CurrentCultureIgnoreCase) &&
                                         method.GetParameters().Select(p => p?.ParameterType).SequenceEqual(propValues?.Select(p => p?.GetType())));

            if (action == null)
            {
                return(new ValidationResult("[RemoteClientServerAttribute] Wskazana metoda walidacji nie istnieje"));
            }

            // Utwórz instancję klasy kontrolera
            var instance = Activator.CreateInstance(controller);
            // Wywołaj metodę akcji posiadającą logikę walidacji
            var response   = action.Invoke(instance, propValues.ToArray());
            var jsonString = response as string;
            var jsonResult = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(jsonString);
            var result     = jsonResult["Result"];
            var message    = jsonResult["Message"] ?? "";

            if (result == null)
            {
                throw new Exception("[RemoteClientServerAttribute] Wynik metody zwrócił null");
            }

            switch ((ActionStatus)result)
            {
            case ActionStatus.Success:
            {
                return(ValidationResult.Success);
            }

            case ActionStatus.Failure:
            {
                return(new ValidationResult(ErrorMessage));    // zwróć wiadomość użytkownika
            }

            case ActionStatus.DatabaseError:
            {
                return(new ValidationResult(message));    // Zwróć wiadomość serwera
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }