Ejemplo n.º 1
0
        public void Initialize(string operation)
        {
            string[] conditionParts = _condition.Split(new string[] { operation }, StringSplitOptions.RemoveEmptyEntries);

            if (conditionParts.Length == 2)
            {
                string leftSide  = conditionParts[0].Trim(),
                       rightSide = conditionParts[1].Trim();

                if (!leftSide.StartsWith("'"))
                {
                    try
                    {
                        LeftSideInt = Int32.Parse(leftSide);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            LeftSide = "'" + ReplaceUtils.GetProperty(leftSide, _resource).ToString() + "'";
                        }
                        catch (Exception) { }
                    }
                }
                else
                {
                    LeftSide = leftSide;
                }

                if (!rightSide.StartsWith("'"))
                {
                    try
                    {
                        RightSideInt = Int32.Parse(rightSide);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            RightSide = "'" + ReplaceUtils.GetProperty(rightSide, _resource).ToString() + "'";
                        }
                        catch (Exception) { }
                    }
                }
                else
                {
                    RightSide = rightSide;
                }
            }
            else
            {
                throw new Exception("Invalid operation in " + _condition);
            }
        }
Ejemplo n.º 2
0
        // This does the replacement at the property level. It tries to replace in the object in the source to the translation
        private static object BuildResponseObject(JObject source, string propertyName, object propertyValue, JObject iterationSource = null)
        {
            // Building response JSON
            if (propertyValue.GetType() == typeof(string))
            {
                string property = (string)propertyValue;

                if (iterationSource != null)
                {
                    object replaced = ReplaceUtils.TransformString(property, iterationSource);
                    if (replaced == null)
                    {
                        replaced = ReplaceUtils.TransformString(property, source);
                    }

                    if (replaced == null)
                    {
                        throw new Exception("Unable to match value \"" + property + "\"");
                    }
                    else
                    {
                        return(replaced);
                    }
                }
                else
                {
                    object replaced = ReplaceUtils.TransformString(property, source);

                    if (replaced == null)
                    {
                        throw new Exception("Unable to match value \"" + property + "\"");
                    }
                    else
                    {
                        return(replaced);
                    }
                }
            }
            else if (propertyValue.GetType() == typeof(JObject))
            {
                return(TransformObject(source, (JObject)propertyValue, iterationSource));
            }
            else if (propertyValue.GetType() == typeof(JArray))
            {
                return(TransformObject(source, (JArray)propertyValue, iterationSource));
            }
            else
            {
                return(propertyValue);
            }
        }
Ejemplo n.º 3
0
 public void gotokdp(int TypeId, int LngId, string parameter)
 {
     try
     {
         if (!string.IsNullOrEmpty(parameter))
         {
             parameter = ReplaceUtils.ReplaceAHerf(parameter);
             if (parameter.Contains(","))
             {
                 if (!ShowEvent.WindowIsOpen(new DocMore().Title))
                 {
                     DocMore more = new DocMore();
                     more.gotokdp += new DocMore.ChangedEventHandler(this.gotokdp);
                     more.StrName  = parameter;
                     more.Show();
                 }
                 return;
             }
             char[] separator = new char[] { '/' };
             TypeId = int.Parse(parameter.Split(separator)[1]);
             char[] chArray2 = new char[] { '/' };
             LngId = int.Parse(parameter.Split(chArray2)[0]);
         }
         if (TypeId == 7)
         {
             new PDF {
                 TypeId = TypeId, ReLngId = LngId.ToString(), Owner = new BasePage().ParentWindow
             }.Show();
         }
         else
         {
             int id = -1;  //todo
             if (TypeId == 3)
             {
                 new PDF {
                     TypeId = TypeId, Id = id, Owner = new BasePage().ParentWindow
                 }.Show();
             }
             else
             {
                 CacheHelper.SetCache(new CacheParameterName().HistoryIndex, string.Empty);
                 CacheHelper.SetCache(this.cache.Id, id.ToString());
                 base.ParentWindow.PageSwitch(this.pageswitch.kdp);
             }
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 4
0
        // This is for when the target translation piece is an array. We need to iterate through it and apply the translation to it children
        private static JArray TransformObject(JObject source, JArray transformation, JObject iterationSource = null)
        {
            List <object> returnJSON = new List <object>();

            foreach (JToken child in transformation.Children())
            {
                if (child.Type == JTokenType.String)
                {
                    returnJSON.Add(ReplaceUtils.TransformString((string)child, source));
                }
                else if (child.GetType() == typeof(JObject))
                {
                    returnJSON.Add(TransformObject(source, (JObject)child, iterationSource));
                }
                else
                {
                    returnJSON.Add(child);
                }
            }

            return(JArray.FromObject(returnJSON));
        }
Ejemplo n.º 5
0
        string IReplacer.Replace(string input, ReplaceTemplateItem item)
        {
            if (item.Replace.Length == 0)
            {
                return(input);
            }

            MatchCollection matches = item.Matches(input);

            Dictionary <Capture, string> map = new Dictionary <Capture, string>();

            foreach (Match match in matches)
            {
                if (ReplaceFilter.CanReplace(input, match, item))
                {
                    Dictionary <int, string> pair = ReplaceReference.Reference(item, match);

                    map[match] = ReplaceUtils.ReplaceMatchValue(match, pair);
                }
            }

            return(ReplaceUtils.GetReplaced(input, map));
        }
Ejemplo n.º 6
0
 public void Assignment()
 {
     try
     {
         base.Width            = this.width;
         this.recordindex.Text = this.index.ToString();
         this.key1.Text        = this.model.Key1;
         this.category.Text    = this.model.CategoryName;
         this.key4.Text        = this.model.Key4;
         this.key2.Text        = this.model.Key2;
         this.intro.Text       = ReplaceUtils.NoHTML(HttpUtility.HtmlDecode(this.model.Intro));
         this.key1.ToolTip     = this.model.Key1;
         this.key4.ToolTip     = this.model.Key4;
         this.key2.ToolTip     = this.model.Key2;
         this.intro.ToolTip    = this.model.Key1;
         this.category.ToolTip = this.model.CategoryName;
         this.dataType.Source  = new BitmapImage(new Uri(string.Format("{0}/icon{1}.png", this.url, this.model.TypeId)));
         if (this.model.SourceID == 9)
         {
             this.selfBuilt.Source = new BitmapImage(new Uri(string.Format("{0}/icon_self.png", this.url)));
         }
         if (string.IsNullOrEmpty(this.model.PDFName) || string.IsNullOrEmpty(this.model.PDFPath))
         {
             this.DownLoad.Visibility = Visibility.Hidden;
         }
         if (this.good != null)
         {
             string keyword   = string.Format("{0}_{1}", this.model.TypeId, this.model.LngId);
             string goodCount = "0";  //todo
             this.Count.Text    = goodCount;
             this.Count.ToolTip = goodCount;
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 7
0
        // This method takes the current position in the transformation and applied the source object to it.
        // If this is part of an iteration loop then the object currently being iterated on is also passed for translation
        private static JObject TransformObject(JObject source, JObject transformation, JObject iterationSource = null)
        {
            // Parsing transformation object

            Dictionary <string, object> returnJSON = new Dictionary <string, object>();
            Dictionary <string, object> serializedTransformation = transformation.ToObject <Dictionary <string, object> >();

            // Loop through all the propertied of the transformation at this level
            foreach (string property in serializedTransformation.Keys)
            {
                // search the current transformation object for any replacement keys in the form {{ ... }}.
                // There may only be 1 replacement on the property level
                Match match = Regex.Match(property, ReplaceUtils.TokenRegex);

                if (match.Success)
                {
                    // Check if the match length is the same as the property length. This is a higher percentage of being a conditional property
                    if (match.Value.Length == property.Length)
                    {
                        string cleanedProperty = StringUtils.CleanProperty(property);

                        // Check if this is a conditional property. Eg is this an IF or an each statement
                        LogicalType?logicalType = LogicalUtils.GetLogicalType(cleanedProperty);

                        if (logicalType.HasValue)
                        {
                            string logicalMask = StringUtils.GetAsMask(cleanedProperty);
                            if (!String.IsNullOrEmpty(logicalMask))
                            {
                                cleanedProperty = StringUtils.GetPropertyWithoutMask(cleanedProperty);
                            }

                            if (logicalType == LogicalType.IF)
                            {
                                // Parse the if to see if it validates out true or false
                                if (LogicalUtils.ParseValidIfCondition(cleanedProperty, source))
                                {
                                    JObject child = TransformObject(source, (JObject)serializedTransformation[property], iterationSource);

                                    if (child != null)
                                    {
                                        // Check if there is a logical mask to be applied. By this, does it have an AS statement included.
                                        // If there is an AS statement then the child object is appended to a poperty named that. If not, it is attached to the parent
                                        if (String.IsNullOrEmpty(logicalMask))
                                        {
                                            Dictionary <string, object> serializedChild = child.ToObject <Dictionary <string, object> >();

                                            foreach (string childProperty in serializedChild.Keys)
                                            {
                                                returnJSON.Add(childProperty, serializedChild[childProperty]);
                                            }
                                        }
                                        else
                                        {
                                            returnJSON.Add(logicalMask, child);
                                        }
                                    }
                                    else
                                    {
                                        return(null);
                                    }
                                }
                                else
                                {
                                    return(null);
                                }
                            }
                            else if (logicalType == LogicalType.EACH)
                            {
                                // Check if there is an AS in the each statement. Eaches need a property to be applied to.
                                if (String.IsNullOrEmpty(logicalMask))
                                {
                                    throw new Exception("Each statements require an AS statement");
                                }

                                IDictionary <string, string> eachProperties = LogicalUtils.ParseEachProperties(cleanedProperty);

                                // Retrieve the property to be iterated on in the each
                                JToken requestedEnumerate = ReplaceUtils.GetProperty(eachProperties["property"], source);

                                JArray iterationArray = new JArray();

                                // Loop through the retrieved object and apply the translation to each entry
                                if (requestedEnumerate.GetType() == typeof(JArray))
                                {
                                    if (serializedTransformation[property].GetType() == typeof(JObject))
                                    {
                                        foreach (JToken child in requestedEnumerate.Children())
                                        {
                                            JObject childObject = new JObject();
                                            childObject.Add(eachProperties["child"], child);

                                            iterationArray.Add(TransformObject(source, (JObject)serializedTransformation[property], childObject));
                                        }
                                    }
                                    else if (serializedTransformation[property].GetType() == typeof(JArray))
                                    {
                                        foreach (JToken child in requestedEnumerate.Children())
                                        {
                                            JObject childObject = new JObject();
                                            childObject.Add(eachProperties["child"], child);

                                            iterationArray.Add(TransformObject(source, (JArray)serializedTransformation[property], childObject));
                                        }
                                    }
                                }
                                else if (requestedEnumerate.GetType() == typeof(JObject))
                                {
                                    JObject childObject = new JObject();
                                    childObject.Add(eachProperties["child"], requestedEnumerate);

                                    if (serializedTransformation[property].GetType() == typeof(JObject))
                                    {
                                        iterationArray.Add(TransformObject(source, (JObject)serializedTransformation[property], childObject));
                                    }
                                    else if (serializedTransformation[property].GetType() == typeof(JArray))
                                    {
                                        iterationArray.Add(TransformObject(source, (JArray)serializedTransformation[property], childObject));
                                    }
                                }

                                // Attach the transated array to a property with the name in the AS statement
                                returnJSON.Add(logicalMask, iterationArray);
                            }
                        }
                        else
                        {
                            string propertyName;

                            // Check if this is part of an EACH statement. If so check that for properties first
                            if (iterationSource != null)
                            {
                                object replaced = ReplaceUtils.TransformString(property, iterationSource);
                                if (replaced == null)
                                {
                                    replaced = ReplaceUtils.TransformString(property, source);
                                }

                                if (replaced == null)
                                {
                                    throw new Exception("Unable to match value \"" + property + "\"");
                                }
                                else
                                {
                                    propertyName = replaced.ToString();
                                }
                            }
                            else
                            {
                                propertyName = ReplaceUtils.TransformString(property, source).ToString();
                            }

                            returnJSON.Add(propertyName, BuildResponseObject(source, property, serializedTransformation[property], iterationSource));
                        }
                    }
                }
                else
                {
                    string propertyName;

                    // Check if this is part of an EACH statement. If so check that for properties first
                    if (iterationSource != null)
                    {
                        object replaced = ReplaceUtils.TransformString(property, iterationSource);
                        if (replaced == null)
                        {
                            replaced = ReplaceUtils.TransformString(property, source);
                        }

                        if (replaced == null)
                        {
                            throw new Exception("Unable to match value \"" + property + "\"");
                        }
                        else
                        {
                            propertyName = replaced.ToString();
                        }
                    }
                    else
                    {
                        propertyName = ReplaceUtils.TransformString(property, source).ToString();
                    }

                    returnJSON.Add(propertyName, BuildResponseObject(source, property, serializedTransformation[property], iterationSource));
                }
            }

            return(JObject.FromObject(returnJSON));
        }