Example #1
0
        internal static SdataTransactionResult GetSdataTransactionResult(List <TransactionResult> transactions, string endpoint, SupportedResourceKinds resource)
        {
            if (transactions == null)
            {
                return(null);
            }
            if (transactions.Count == 0)
            {
                return(null);
            }

            GuidConverter          guidConverter = new GuidConverter();
            SdataTransactionResult result;

            foreach (TransactionResult transaction in transactions)
            {
                if (transaction.Status != TransactionStatus.Success)
                {
                    result = new SdataTransactionResult();
                    result.ResourceKind = resource;
                    result.LocalId      = transaction.ID;
                    try
                    {
                        result.Uuid = (Guid)guidConverter.ConvertFromString(transaction.CRMID);
                    }
                    catch (Exception)
                    { }
                    result.HttpMessage = transaction.Message;
                    result.Location    = endpoint + "('" + transaction.ID + "')";
                    result.HttpStatus  = Helper.GetHttpStatus(transaction.Status, transaction.Action);
                    result.HttpMethod  = Helper.GetHttpMethod(transaction.Action);
                    return(result);
                }
            }
            if (transactions.Count == 0)
            {
                return(null);
            }

            result = new SdataTransactionResult();
            result.ResourceKind = resource;
            result.LocalId      = transactions[0].ID;
            try
            {
                result.Uuid = (Guid)guidConverter.ConvertFromString(transactions[0].CRMID);
            }
            catch (Exception)
            { }
            result.HttpMessage = transactions[0].Message;
            result.Location    = endpoint + "('" + transactions[0].ID + "')";
            result.HttpStatus  = Helper.GetHttpStatus(transactions[0].Status, transactions[0].Action);
            result.HttpMethod  = Helper.GetHttpMethod(transactions[0].Action);
            return(result);
        }
Example #2
0
        private string GetTradingAccountLocalId(string uuidString)
        {
            GuidConverter converter = new GuidConverter();

            try
            {
                Guid uuid = (Guid)converter.ConvertFromString(uuidString);
                return(GetTradingAccountLocalId(uuid));
            }
            catch (Exception)
            {
                return("");
            }
        }
Example #3
0
        private Guid StringToGuid(string guid)
        {
            try
            {
                GuidConverter converter = new GuidConverter();

                Guid result = (Guid)converter.ConvertFromString(guid);
                return(result);
            }
            catch
            {
                return(Guid.Empty);
            }
        }
        private string GetLocalId(string uuidString, SupportedResourceKinds resKind)
        {
            GuidConverter converter = new GuidConverter();

            try
            {
                Guid uuid = (Guid)converter.ConvertFromString(uuidString);
                return(GetLocalId(uuid, resKind));
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
Example #5
0
        private string Getproductfamilyid(string uuidString)
        {
            GuidConverter converter = new GuidConverter();

            try
            {
                Guid uuid = (Guid)converter.ConvertFromString(uuidString);
                return(Getproductfamilyid(uuid));
            }
            catch (Exception)
            {
                return("");
            }
        }
        protected string GetLocalId(string uuidString)
        {
            GuidConverter converter = new GuidConverter();

            try
            {
                Guid uuid = (Guid)converter.ConvertFromString(uuidString);
                return(GetLocalId(uuid));
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
Example #7
0
        private bool GetByteStreams(string classname, string configname, out byte[] clsid_stream, out byte[] config_stream)
        {
            clsid_stream  = null;
            config_stream = null;
            Microsoft.Win32.RegistryKey rk_class = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, "").OpenSubKey("Software\\SySal2\\Classes\\" + classname);
            string clsidstr = rk_class.GetValue("CLSID").ToString();

            rk_class.Close();
            try
            {
                GuidConverter g     = new GuidConverter();
                Guid          clsid = (Guid)g.ConvertFromString(clsidstr);
                clsid_stream = clsid.ToByteArray();
                Microsoft.Win32.RegistryKey rk_config = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, "").OpenSubKey("Software\\SySal2\\Configs\\" + configname);
                string[] names = rk_config.GetValueNames();
                config_stream    = new byte[4 + names.Length * 128];
                config_stream[0] = Convert.ToByte(names.Length & 0xff);
                config_stream[1] = Convert.ToByte((names.Length >> 8) & 0xff);
                config_stream[2] = Convert.ToByte((names.Length >> 16) & 0xff);
                config_stream[3] = Convert.ToByte((names.Length >> 24) & 0xff);
                int i, j;
                for (i = 0; i < names.Length; i++)
                {
                    for (j = 0; j < 64 && j < names[i].Length; j++)
                    {
                        config_stream[4 + i * 128 + j] = (byte)names[i][j];
                    }
                    while (j < 64)
                    {
                        config_stream[4 + i * 128 + j++] = (byte)0;
                    }
                    string value = rk_config.GetValue(names[i]).ToString();
                    for (j = 0; j < 64 && j < value.Length; j++)
                    {
                        config_stream[68 + i * 128 + j] = (byte)value[j];
                    }
                    while (j < 64)
                    {
                        config_stream[68 + i * 128 + j++] = (byte)0;
                    }
                }
                rk_config.Close();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
        private Guid GetUuid(string localId, string uuidString, SupportedResourceKinds resKind)
        {
            if (String.IsNullOrEmpty(localId))
            {
                return(Guid.Empty);
            }

            CorrelatedResSyncInfo[] results = _correlatedResSyncInfoStore.GetByLocalId(resKind.ToString(),
                                                                                       new string[] { localId });
            if (results.Length > 0)
            {
                return(results[0].ResSyncInfo.Uuid);
            }
            Guid result;

            if (string.IsNullOrEmpty(uuidString))
            {
                result = Guid.NewGuid();
            }
            else
            {
                try
                {
                    GuidConverter converter = new GuidConverter();
                    result = (Guid)converter.ConvertFromString(uuidString);
                    if (Guid.Empty.Equals(result))
                    {
                        result = Guid.NewGuid();
                    }
                }
                catch (Exception)
                {
                    result = Guid.NewGuid();
                }
            }

            ResSyncInfo           newResSyncInfo = new ResSyncInfo(result, _context.DatasetLink + resKind.ToString(), 0, string.Empty, DateTime.Now);
            CorrelatedResSyncInfo newCorrelation = new CorrelatedResSyncInfo(localId, newResSyncInfo);

            _correlatedResSyncInfoStore.Put(resKind.ToString(), newCorrelation);
            return(result);
        }
        protected Guid GetUuid(string localId, string uuidString)
        {
            if (String.IsNullOrEmpty(localId))
            {
                return(Guid.Empty);
            }

            CorrelatedResSyncInfo[] results = _correlatedResSyncInfoStore.GetByLocalId(_resourceKindString, new string[] { localId });
            if (results.Length > 0)
            {
                return(results[0].ResSyncInfo.Uuid);
            }
            Guid result;

            if (string.IsNullOrEmpty(uuidString))
            {
                result = Guid.NewGuid();
            }
            else
            {
                try
                {
                    GuidConverter converter = new GuidConverter();
                    result = (Guid)converter.ConvertFromString(uuidString);
                    if (Guid.Empty.Equals(result))
                    {
                        result = Guid.NewGuid();
                    }
                }
                catch (Exception)
                {
                    result = Guid.NewGuid();
                }
            }

            ResSyncInfo           newResSyncInfo = new ResSyncInfo(result, _originApplication, 0, string.Empty, DateTime.Now);
            CorrelatedResSyncInfo newCorrelation = new CorrelatedResSyncInfo(localId, newResSyncInfo);

            _correlatedResSyncInfoStore.Put(_resourceKindString, newCorrelation);
            return(result);
        }
        private void PersistRelations(List <TransactionResult> transactions)
        {
            GuidConverter guidConverter = new GuidConverter();

            foreach (TransactionResult transaction in transactions)
            {
                if (transaction.Status == TransactionStatus.Success)
                {
                    SupportedResourceKinds resourceKind = GetSupportedResourceKind(transaction.EntityName);
                    if (resourceKind == SupportedResourceKinds.None)
                    {
                        continue;
                    }

                    string uuidString = transaction.CRMID;
                    Guid   uuid       = Guid.Empty;
                    try
                    {
                        uuid = (Guid)guidConverter.ConvertFromString(uuidString);
                    }
                    catch
                    {
                        continue;
                    }
                    if (uuid == Guid.Empty)
                    {
                        continue;
                    }

                    string      localId     = transaction.ID;
                    ResSyncInfo resSyncInfo = new ResSyncInfo(uuid, _context.DatasetLink + resourceKind.ToString(), -1, "", DateTime.Now);

                    CorrelatedResSyncInfo correlatedResSyncInfo = new CorrelatedResSyncInfo(localId, resSyncInfo);

                    // store the new correlation to the sync store
                    _correlatedResSyncInfoStore.Put(resourceKind.ToString(), correlatedResSyncInfo);
                }
            }
        }
        public void ReadXml(System.Xml.XmlReader reader, Type payloadType)
        {
            GuidConverter guidConverter = new GuidConverter();

            if ((reader.NodeType == System.Xml.XmlNodeType.Element) &&
                (reader.LocalName == "entry") &&
                (reader.NamespaceURI == Namespaces.atomNamespace))
            {
                bool reading = true;
                while (reading)
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        switch (reader.LocalName)
                        {
                        case "title":
                            reading = reader.Read();
                            if (reader.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                this.Title = reader.Value;
                            }
                            break;

                        case "id":
                            reading = reader.Read();
                            if (reader.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                this.Id = reader.Value;
                            }
                            break;

                        case "uuid":
                            reading = reader.Read();
                            if (reader.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                string uuidString = reader.Value;

                                this.Uuid = (Guid)guidConverter.ConvertFromString(uuidString);
                            }
                            break;

                        case "httpStatus":
                            reading = reader.Read();
                            if (reader.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                this.HttpStatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), reader.Value);
                            }
                            break;

                        case "httpMessage":
                            reading = reader.Read();
                            if (reader.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                this.HttpMessage = reader.Value;
                            }
                            break;

                        case "location":
                            reading = reader.Read();
                            if (reader.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                this.HttpLocation = reader.Value;
                            }
                            break;

                        case "httpMethod":
                            reading = reader.Read();
                            if (reader.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                this.HttpMethod = reader.Value;
                            }
                            break;

                        case "payload":
                            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(payloadType);
                            object obj = serializer.Deserialize(reader);
                            if (obj is PayloadBase)
                            {
                                this.Payload = obj as PayloadBase;
                            }
                            break;

                        case "syncState":
                            System.Xml.Serialization.XmlSerializer syncStateSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SyncState));
                            object obj1 = syncStateSerializer.Deserialize(reader);
                            if (obj1 is SyncState)
                            {
                                this.SyncState = obj1 as SyncState;
                            }
                            break;

                        case "link":

                            if (reader.HasAttributes)
                            {
                                SyncFeedEntryLink link = new SyncFeedEntryLink();
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.LocalName.Equals("payloadpath", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        link.PayloadPath = reader.Value;
                                    }
                                    if (reader.LocalName.Equals("rel", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        link.LinkRel = reader.Value;
                                    }
                                    if (reader.LocalName.Equals("type", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        link.LinkType = reader.Value;
                                    }
                                    if (reader.LocalName.Equals("title", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        link.Title = reader.Value;
                                    }
                                    if (reader.LocalName.Equals("uuid", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        link.Uuid = reader.Value;
                                    }
                                    if (reader.LocalName.Equals("href", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        link.Href = reader.Value;
                                    }
                                }

                                this.SyncLinks.Add(link);
                            }
                            break;

                        case "linked":
                            System.Xml.Serialization.XmlSerializer linkedSerializer = new System.Xml.Serialization.XmlSerializer(typeof(LinkedElement));
                            object linkedObj = linkedSerializer.Deserialize(reader);
                            if (linkedObj is LinkedElement)
                            {
                                this.Linked = linkedObj as LinkedElement;
                            }
                            break;


                        default:
                            reading = reader.Read();
                            break;
                        }
                    }
                    else
                    {
                        if ((reader.NodeType == System.Xml.XmlNodeType.EndElement) &&
                            (reader.LocalName == "entry"))
                        {
                            reading = false;
                        }
                        else
                        {
                            reading = reader.Read();
                        }
                    }
                }
            }
        }